From 9d0d4b9946e3c979c5d01755c2d41e52153f6aa0 Mon Sep 17 00:00:00 2001 From: Meow King Date: Mon, 5 Aug 2024 21:28:01 +0800 Subject: [PATCH] refactor: rename class so that it can be built on python version less than 3.12 (no stable abi) --- CMakeLists.txt | 22 +- pyproject.toml | 7 +- src/llvm/Analysis.cpp | 4 +- src/llvm/Core/enum.cpp | 26 +- src/llvm/Core/globalFunc.cpp | 2 +- src/llvm/Core/iterator.cpp | 18 +- src/llvm/Core/miscClasses.cpp | 864 ++++++------- src/llvm/Core/miscClasses.h | 8 +- src/llvm/Core/type.cpp | 278 ++--- src/llvm/Core/utils.cpp | 150 +-- src/llvm/Core/utils.h | 16 +- src/llvm/Core/value.cpp | 1066 ++++++++--------- src/llvm/Core/value.h | 10 +- src/llvm/TargetMachine.cpp | 70 +- src/llvm/Utils.cpp | 4 +- src/llvm/types_priv.h | 302 ++--- src/llvm/types_priv/PyMemoryBuffer.cpp | 55 - src/llvm/types_priv/PyMetadataEntries.cpp | 17 - src/llvm/types_priv/PyModuleFlagEntries.cpp | 15 - src/llvm/types_priv/PyModuleProvider.cpp | 11 - src/llvm/types_priv/PyOperandBundle.cpp | 13 - src/llvm/types_priv/PyPassManagerBase.cpp | 11 - src/llvm/types_priv/PyTargetData.cpp | 11 - src/llvm/types_priv/PyTargetMachine.cpp | 12 - .../types_priv/PyTargetMachineOptions.cpp | 12 - .../{PyContext.cpp => PymContext.cpp} | 40 +- .../types_priv/{PyContext.h => PymContext.h} | 12 +- .../{PyLLVMObject.h => PymLLVMObject.h} | 6 +- src/llvm/types_priv/PymMemoryBuffer.cpp | 55 + .../{PyMemoryBuffer.h => PymMemoryBuffer.h} | 8 +- src/llvm/types_priv/PymMetadataEntries.cpp | 17 + ...MetadataEntries.h => PymMetadataEntries.h} | 6 +- .../{PyModule.cpp => PymModule.cpp} | 12 +- .../types_priv/{PyModule.h => PymModule.h} | 10 +- src/llvm/types_priv/PymModuleFlagEntries.cpp | 15 + ...leFlagEntries.h => PymModuleFlagEntries.h} | 6 +- src/llvm/types_priv/PymModuleProvider.cpp | 11 + ...PyModuleProvider.h => PymModuleProvider.h} | 6 +- src/llvm/types_priv/PymOperandBundle.cpp | 13 + .../{PyOperandBundle.h => PymOperandBundle.h} | 6 +- src/llvm/types_priv/PymPassManagerBase.cpp | 11 + ...PassManagerBase.h => PymPassManagerBase.h} | 6 +- src/llvm/types_priv/PymTargetData.cpp | 11 + .../{PyTargetData.h => PymTargetData.h} | 6 +- src/llvm/types_priv/PymTargetMachine.cpp | 12 + .../{PyTargetMachine.h => PymTargetMachine.h} | 6 +- .../types_priv/PymTargetMachineOptions.cpp | 12 + ...ineOptions.h => PymTargetMachineOptions.h} | 6 +- src/llvmpym_ext.cpp | 2 +- 49 files changed, 1649 insertions(+), 1650 deletions(-) delete mode 100644 src/llvm/types_priv/PyMemoryBuffer.cpp delete mode 100644 src/llvm/types_priv/PyMetadataEntries.cpp delete mode 100644 src/llvm/types_priv/PyModuleFlagEntries.cpp delete mode 100644 src/llvm/types_priv/PyModuleProvider.cpp delete mode 100644 src/llvm/types_priv/PyOperandBundle.cpp delete mode 100644 src/llvm/types_priv/PyPassManagerBase.cpp delete mode 100644 src/llvm/types_priv/PyTargetData.cpp delete mode 100644 src/llvm/types_priv/PyTargetMachine.cpp delete mode 100644 src/llvm/types_priv/PyTargetMachineOptions.cpp rename src/llvm/types_priv/{PyContext.cpp => PymContext.cpp} (63%) rename src/llvm/types_priv/{PyContext.h => PymContext.h} (69%) rename src/llvm/types_priv/{PyLLVMObject.h => PymLLVMObject.h} (85%) create mode 100644 src/llvm/types_priv/PymMemoryBuffer.cpp rename src/llvm/types_priv/{PyMemoryBuffer.h => PymMemoryBuffer.h} (62%) create mode 100644 src/llvm/types_priv/PymMetadataEntries.cpp rename src/llvm/types_priv/{PyMetadataEntries.h => PymMetadataEntries.h} (68%) rename src/llvm/types_priv/{PyModule.cpp => PymModule.cpp} (55%) rename src/llvm/types_priv/{PyModule.h => PymModule.h} (55%) create mode 100644 src/llvm/types_priv/PymModuleFlagEntries.cpp rename src/llvm/types_priv/{PyModuleFlagEntries.h => PymModuleFlagEntries.h} (68%) create mode 100644 src/llvm/types_priv/PymModuleProvider.cpp rename src/llvm/types_priv/{PyModuleProvider.h => PymModuleProvider.h} (66%) create mode 100644 src/llvm/types_priv/PymOperandBundle.cpp rename src/llvm/types_priv/{PyOperandBundle.h => PymOperandBundle.h} (65%) create mode 100644 src/llvm/types_priv/PymPassManagerBase.cpp rename src/llvm/types_priv/{PyPassManagerBase.h => PymPassManagerBase.h} (65%) create mode 100644 src/llvm/types_priv/PymTargetData.cpp rename src/llvm/types_priv/{PyTargetData.h => PymTargetData.h} (67%) create mode 100644 src/llvm/types_priv/PymTargetMachine.cpp rename src/llvm/types_priv/{PyTargetMachine.h => PymTargetMachine.h} (66%) create mode 100644 src/llvm/types_priv/PymTargetMachineOptions.cpp rename src/llvm/types_priv/{PyTargetMachineOptions.h => PymTargetMachineOptions.h} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e94820..cdb4c96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) diff --git a/pyproject.toml b/pyproject.toml index 428c40c..c9859e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, @@ -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] diff --git a/src/llvm/Analysis.cpp b/src/llvm/Analysis.cpp index 21c59a8..5264011 100644 --- a/src/llvm/Analysis.cpp +++ b/src/llvm/Analysis.cpp @@ -18,7 +18,7 @@ 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, @@ -26,7 +26,7 @@ void populateAnalysis(nb::module_ &m) { "Useful for debugging."); m.def("view_function_cfg_only", - [](PyFunction &f) { + [](PymFunction &f) { return LLVMViewFunctionCFGOnly(f.get()); }, "fn"_a, diff --git a/src/llvm/Core/enum.cpp b/src/llvm/Core/enum.cpp index b81d33c..73de109 100644 --- a/src/llvm/Core/enum.cpp +++ b/src/llvm/Core/enum.cpp @@ -375,9 +375,9 @@ void bindEnums(nb::module_ &m) { "However, duplicate entries in the second list are dropped during " "the append operation."); - nb::enum_(m, "AttributeIndex", "AttributeIndex") - .value("Return", PyAttributeIndex::Return) - .value("Function", PyAttributeIndex::Function); + nb::enum_(m, "AttributeIndex", "AttributeIndex") + .value("Return", PymAttributeIndex::Return) + .value("Function", PymAttributeIndex::Function); nb::enum_(m, "TailCallKind", "TailCallKind") .value("LLVMTailCallKindNone", LLVMTailCallKind::LLVMTailCallKindNone) @@ -387,16 +387,16 @@ void bindEnums(nb::module_ &m) { // TODO LLVMAttributeIndex - nb::enum_(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_(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 } diff --git a/src/llvm/Core/globalFunc.cpp b/src/llvm/Core/globalFunc.cpp index 44168ca..736fe56 100644 --- a/src/llvm/Core/globalFunc.cpp +++ b/src/llvm/Core/globalFunc.cpp @@ -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 diff --git a/src/llvm/Core/iterator.cpp b/src/llvm/Core/iterator.cpp index b29f775..01438a9 100644 --- a/src/llvm/Core/iterator.cpp +++ b/src/llvm/Core/iterator.cpp @@ -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") } diff --git a/src/llvm/Core/miscClasses.cpp b/src/llvm/Core/miscClasses.cpp index 0f44bd8..d22a7ec 100644 --- a/src/llvm/Core/miscClasses.cpp +++ b/src/llvm/Core/miscClasses.cpp @@ -20,7 +20,7 @@ using optional = std::optional; void bindOtherClasses(nb::module_ &m) { auto ContextClass = - nb::class_> + nb::class_> (m, "Context", "Contexts are execution states for the core LLVM IR system.\n\n" "Most types are tied to a context instance. Multiple contexts can" @@ -28,83 +28,83 @@ void bindOtherClasses(nb::module_ &m) { "different contexts can execute on different threads simultaneously."); auto AttributeClass = - nb::class_> + nb::class_> (m, "Attribute", "Attribute"); - auto EnumAttributeClass = nb::class_ + auto EnumAttributeClass = nb::class_ (m, "EnumAttribute", "EnumAttribute"); - auto TypeAttributeClass = nb::class_ + auto TypeAttributeClass = nb::class_ (m, "TypeAttribute", "TypeAttribute"); - auto StringAttributeClass = nb::class_ + auto StringAttributeClass = nb::class_ (m, "StringAttribute", "StringAttribute"); auto BasicBlockClass = - nb::class_> + nb::class_> (m, "BasicBlock", "BasicBlock"); auto DiagnosticInfoClass = - nb::class_> + nb::class_> (m, "DiagnosticInfo", "DiagnosticInfo"); auto NamedMDNodeClass = - nb::class_> + nb::class_> (m, "NamedMDNode", "NamedMDNode"); auto ModuleClass = - nb::class_> + nb::class_> (m, "Module", "Modules represent the top-level structure in an LLVM program. An LLVM" "module is effectively a translation unit or a collection of translation " "units merged together."); auto ModuleFlagEntriesClass = - nb::class_> + nb::class_> (m, "ModuleFlagEntry", "ModuleFlagEntry"); auto MetadataClass = - nb::class_> + nb::class_> (m, "Metadata", "Metadata"); - auto MDNodeClass = nb::class_(m, "MDNode", "MDNode"); - auto MDStringClass = nb::class_(m, "MDString", "MDString"); - auto ValueAsMetadata = nb::class_ + auto MDNodeClass = nb::class_(m, "MDNode", "MDNode"); + auto MDStringClass = nb::class_(m, "MDString", "MDString"); + auto ValueAsMetadata = nb::class_ (m, "ValueAsMetadata", "ValueAsMetadata"); auto MetadataEntriesClass = - nb::class_> + nb::class_> (m, "MetadataEntry", "MetadataEntry"); auto UseClass = - nb::class_> + nb::class_> (m, "Use", "Use"); auto IntrinsicClass = - // nb::class_> - nb::class_> + // nb::class_> + nb::class_> (m, "Intrinsic", "Intrinsic"); auto OperandBundleClass = - nb::class_> + nb::class_> (m, "OperandBundle", "OperandBundle"); auto BuilderClass = - nb::class_> + nb::class_> (m, "Builder", "Builder"); auto ModuleProviderClass = - nb::class_> + nb::class_> (m, "ModuleProvider", "ModuleProvider"); auto MemoryBufferClass = - nb::class_> + nb::class_> (m, "MemoryBuffer", "MemoryBuffer"); - // no need to create PyPassManagerBase binding + // no need to create PymPassManagerBase binding auto PassManagerClass = - nb::class_> + nb::class_> (m, "PassManager", "PassManager"); - auto FunctionPassManagerClass = nb::class_ + auto FunctionPassManagerClass = nb::class_ (m, "FunctionPassManager", "FunctionPassManager"); MetadataClass .def("__repr__", - [](PyMetadata &self) { + [](PymMetadata &self) { return ""; }) .def_static("get_md_kind_id", @@ -113,62 +113,62 @@ void bindOtherClasses(nb::module_ &m) { }, "name"_a = "") .def("as_value", - [](PyMetadata &self, PyContext &c) { - return PyMetadataAsValue(LLVMMetadataAsValue(c.get(), self.get())); + [](PymMetadata &self, PymContext &c) { + return PymMetadataAsValue(LLVMMetadataAsValue(c.get(), self.get())); }, "context"_a); MDStringClass .def("__repr__", - [](PyMDString &self) { + [](PymMDString &self) { return ""; }) .def("__init__", - [](PyMDString *mds, PyContext &context, std::string &name) { - new (mds) PyMDString(LLVMMDStringInContext2 + [](PymMDString *mds, PymContext &context, std::string &name) { + new (mds) PymMDString(LLVMMDStringInContext2 (context.get(), name.c_str(), name.size())); }, "context"_a, "name"_a = "", "Create an MDString value from a given string value.") .def("as_value", - [](PyMDString &self, PyContext &c) { - return PyMDStringValue(LLVMMetadataAsValue(c.get(), self.get())); + [](PymMDString &self, PymContext &c) { + return PymMDStringValue(LLVMMetadataAsValue(c.get(), self.get())); }, "context"_a); MDNodeClass .def("__repr__", - [](PyMDNode &self) { + [](PymMDNode &self) { return ""; }) .def("__init__", - [](PyMDNode *mdd, PyContext &c, std::vector mds) { + [](PymMDNode *mdd, PymContext &c, std::vector mds) { size_t num = mds.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMMetadataRef, mds, raw, num); - new (mdd) PyMDNode(LLVMMDNodeInContext2(c.get(), raw.data(), num)); + new (mdd) PymMDNode(LLVMMDNodeInContext2(c.get(), raw.data(), num)); }, "context"_a, "metadata"_a) .def("as_value", - [](PyMDNode &self, PyContext &c) { - return PyMDNodeValue(LLVMMetadataAsValue(c.get(), self.get())); + [](PymMDNode &self, PymContext &c) { + return PymMDNodeValue(LLVMMetadataAsValue(c.get(), self.get())); }, "context"_a); PassManagerClass .def("__repr__", - [](PyPassManager &self) { + [](PymPassManager &self) { return ""; }) .def("__init__", - [](PyPassManager *pm) { - new (pm) PyPassManager(LLVMCreatePassManager()); + [](PymPassManager *pm) { + new (pm) PymPassManager(LLVMCreatePassManager()); }, "Constructs a new whole-module pass pipeline. This type of pipeline is" "suitable for link-time optimization and whole-module transformations.") .def("run", - [](PyPassManager &self, PyModule &module) { + [](PymPassManager &self, PymModule &module) { return LLVMRunPassManager(self.get(), module.get()) != 0; }, "module"_a, @@ -178,12 +178,12 @@ void bindOtherClasses(nb::module_ &m) { FunctionPassManagerClass .def("__repr__", - [](PyFunctionPassManager &self) { + [](PymFunctionPassManager &self) { return ""; }) .def("__init__", - [](PyFunctionPassManager *fpm, PyModule &module) { - new (fpm) PyFunctionPassManager(LLVMCreateFunctionPassManagerForModule + [](PymFunctionPassManager *fpm, PymModule &module) { + new (fpm) PymFunctionPassManager(LLVMCreateFunctionPassManagerForModule (module.get())); }, "module"_a, @@ -191,14 +191,14 @@ void bindOtherClasses(nb::module_ &m) { "provider. It does not take ownership of the module provider. This type of" "pipeline is suitable for code generation and JIT compilation tasks.") .def("initialize", - [](PyFunctionPassManager &self) { + [](PymFunctionPassManager &self) { return LLVMInitializeFunctionPassManager(self.get()) != 0; }, "Initializes all of the function passes scheduled in the function pass" "manager. Returns true if any of the passes modified the module, false " "otherwise.") .def("run", - [](PyFunctionPassManager &self, PyFunction f) { + [](PymFunctionPassManager &self, PymFunction f) { return LLVMRunFunctionPassManager(self.get(), f.get()) != 0; }, "f"_a, @@ -206,7 +206,7 @@ void bindOtherClasses(nb::module_ &m) { "on the provided function. Returns true if any of the passes modified the" "function, false otherwise.") .def("finalize", - [](PyFunctionPassManager &self) { + [](PymFunctionPassManager &self) { return LLVMFinalizeFunctionPassManager(self.get()) != 0; }, "Finalizes all of the function passes scheduled in the function pass" @@ -215,18 +215,18 @@ void bindOtherClasses(nb::module_ &m) { ModuleProviderClass .def("__repr__", - [](PyModuleProvider &self) { + [](PymModuleProvider &self) { return ""; }) .def("create_function_pass_manager", - [](PyModuleProvider &self) { - return PyFunctionPassManager(LLVMCreateFunctionPassManager(self.get())); + [](PymModuleProvider &self) { + return PymFunctionPassManager(LLVMCreateFunctionPassManager(self.get())); }, "Deprecated: Use :func:`Module.create_function_pass_manager` instead."); MemoryBufferClass .def("__repr__", - [](PyMemoryBuffer &self) { + [](PymMemoryBuffer &self) { return ""; }) .def_static("from_file", @@ -239,7 +239,7 @@ void bindOtherClasses(nb::module_ &m) { throw std::runtime_error(OutMessage); } - return PyMemoryBuffer(OutMemBuf); + return PymMemoryBuffer(OutMemBuf); }, "path"_a, ":raises RuntimeError") @@ -252,91 +252,91 @@ void bindOtherClasses(nb::module_ &m) { if (!success) { throw std::runtime_error(OutMessage); } - return PyMemoryBuffer(OutMemBuf); + return PymMemoryBuffer(OutMemBuf); }, ":raises RuntimeError") .def_static("from_str", [](std::string &inputData, bool RequiresNullTerminator, const char *BufferName) { - return PyMemoryBuffer(LLVMCreateMemoryBufferWithMemoryRange + return PymMemoryBuffer(LLVMCreateMemoryBufferWithMemoryRange (inputData.c_str(), inputData.size(), BufferName, RequiresNullTerminator)); }, "input_data"_a, "requires_null_terminator"_a, "buffer_name"_a = "") .def_static("from_str", [](const std::string &inputData, const char *BufferName) -> - optional{ + optional{ auto res = LLVMCreateMemoryBufferWithMemoryRangeCopy (inputData.c_str(), inputData.size(), BufferName); - WRAP_OPTIONAL_RETURN(res, PyMemoryBuffer); + WRAP_OPTIONAL_RETURN(res, PymMemoryBuffer); }, "input_data"_a, "buffer_name"_a = "") .def_prop_ro("buffer_start", - [](PyMemoryBuffer &self) { + [](PymMemoryBuffer &self) { return LLVMGetBufferStart(self.get()); }) .def_prop_ro("buffer_size", - [](PyMemoryBuffer &self) { + [](PymMemoryBuffer &self) { return LLVMGetBufferSize(self.get()); }); BuilderClass .def("__repr__", - [](PyBuilder &self) { + [](PymBuilder &self) { return ""; }) .def("__init__", - [](PyBuilder *b, PyContext &c) { - new (b) PyBuilder(LLVMCreateBuilderInContext(c.get())); + [](PymBuilder *b, PymContext &c) { + new (b) PymBuilder(LLVMCreateBuilderInContext(c.get())); }) .def("__init__", - [](PyBuilder *b) { - new (b) PyBuilder(LLVMCreateBuilder()); + [](PymBuilder *b) { + new (b) PymBuilder(LLVMCreateBuilder()); }) .def_prop_ro("insert_block", - [](PyBuilder &self) { - return PyBasicBlock(LLVMGetInsertBlock(self.get())); + [](PymBuilder &self) { + return PymBasicBlock(LLVMGetInsertBlock(self.get())); }) // note LLVMSetCurrentDebugLocation is deprecated in favor of // LLVMSetCurrentDebugLocation2. Also the LLVMGetCurrentDebugLocation .def_prop_rw("current_debug_location", - [](PyBuilder &self) { - return PyMetadata(LLVMGetCurrentDebugLocation2(self.get())); + [](PymBuilder &self) { + return PymMetadata(LLVMGetCurrentDebugLocation2(self.get())); }, - [](PyBuilder &self, PyMetadata &loc) { + [](PymBuilder &self, PymMetadata &loc) { return LLVMSetCurrentDebugLocation2(self.get(), loc.get()); }) .def_prop_rw("default_fp_math_tag", - [](PyBuilder &self) { - return PyMetadata(LLVMBuilderGetDefaultFPMathTag(self.get())); + [](PymBuilder &self) { + return PymMetadata(LLVMBuilderGetDefaultFPMathTag(self.get())); }, - [](PyBuilder &self, PyMetadata &fpMathTag) { + [](PymBuilder &self, PymMetadata &fpMathTag) { return LLVMBuilderSetDefaultFPMathTag(self.get(), fpMathTag.get()); }, nb::for_getter("Get the dafult floating-point math metadata.")) .def("position", - [](PyBuilder &self, PyBasicBlock bb, PyInstruction &inst) { + [](PymBuilder &self, PymBasicBlock bb, PymInstruction &inst) { return LLVMPositionBuilder(self.get(), bb.get(), inst.get()); }, "Original Function: LLVMPositionBuilder.") .def("position_before", - [](PyBuilder &self, PyInstruction &inst) { + [](PymBuilder &self, PymInstruction &inst) { return LLVMPositionBuilderBefore(self.get(), inst.get()); }, "instruction"_a, "Original function: LLVMPositionBuilderBefore.") .def("position_at_end", - [](PyBuilder &self, PyBasicBlock bb) { + [](PymBuilder &self, PymBasicBlock bb) { return LLVMPositionBuilderAtEnd(self.get(), bb.get()); }, "basicblock"_a, "Original function: LLVMPositionBuilderAtEnd.") .def("clear_insert_position", - [](PyBuilder &self) { + [](PymBuilder &self) { return LLVMClearInsertionPosition(self.get()); }) .def("insert", - [](PyBuilder &self, PyBasicBlock &bb) { + [](PymBuilder &self, PymBasicBlock &bb) { return LLVMInsertExistingBasicBlockAfterInsertBlock(self.get(), bb.get()); }, "basic_block"_a, @@ -344,22 +344,22 @@ void bindOtherClasses(nb::module_ &m) { "builder.\n\n" "The insertion point must be valid.") .def("insert", - [](PyBuilder &self, PyInstruction &inst) { + [](PymBuilder &self, PymInstruction &inst) { return LLVMInsertIntoBuilder(self.get(), inst.get()); }, "instruction"_a) .def("insert_with_name", - [](PyBuilder &self, PyInstruction &inst, const char *name) { + [](PymBuilder &self, PymInstruction &inst, const char *name) { return LLVMInsertIntoBuilderWithName(self.get(), inst.get(), name); }, "instruction"_a, "name"_a = "") .def("destory", - [](PyBuilder &self) { + [](PymBuilder &self) { return LLVMDisposeBuilder(self.get()); }, "Original Function: LLVMDisposeBuilder.") .def("set_instruction_debug_location", - [](PyBuilder &self, PyInstruction &inst) { + [](PymBuilder &self, PymInstruction &inst) { return LLVMSetInstDebugLocation(self.get(), inst.get()); }, "instruction"_a, @@ -367,7 +367,7 @@ void bindOtherClasses(nb::module_ &m) { "current debug location for the given builder. If the builder has no current" "debug location, this function is a no-op.") .def("add_metadata_to_instruction", - [](PyBuilder &self, PyInstruction &inst) { + [](PymBuilder &self, PymInstruction &inst) { return LLVMAddMetadataToInst(self.get(), inst.get()); }, "instruction"_a, @@ -377,63 +377,63 @@ void bindOtherClasses(nb::module_ &m) { * The following methods are used to build instructions * the returned instructions are as specific are possible * But if the instruction type doesn't meant to be used in other API functions, - * then we make it as PyInstruction Type to reduce the Instruction sub-classes number + * then we make it as PymInstruction Type to reduce the Instruction sub-classes number */ .def("ret_void", - [](PyBuilder &self) { - return PyReturnInst(LLVMBuildRetVoid(self.get())); + [](PymBuilder &self) { + return PymReturnInst(LLVMBuildRetVoid(self.get())); }) .def("ret", - [](PyBuilder &self, PyValue &v) { - return PyReturnInst(LLVMBuildRet(self.get(), v.get())); + [](PymBuilder &self, PymValue &v) { + return PymReturnInst(LLVMBuildRet(self.get(), v.get())); }, "value"_a) .def("aggregate_ret", - [](PyBuilder &self, std::vector &values) { + [](PymBuilder &self, std::vector &values) { unsigned num = values.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, values, raw, num); - return PyReturnInst(LLVMBuildAggregateRet(self.get(), raw.data(), num)); + return PymReturnInst(LLVMBuildAggregateRet(self.get(), raw.data(), num)); }, "values"_a) .def("br", - [](PyBuilder &self, PyBasicBlock &dest) { - return PyBranchInst(LLVMBuildBr(self.get(), dest.get())); + [](PymBuilder &self, PymBasicBlock &dest) { + return PymBranchInst(LLVMBuildBr(self.get(), dest.get())); }, "dest"_a) .def("cond_br", - [](PyBuilder &self, PyValue &If, PyBasicBlock &Then, - PyBasicBlock &Else) { - return PyBranchInst(LLVMBuildCondBr(self.get(), If.get(), + [](PymBuilder &self, PymValue &If, PymBasicBlock &Then, + PymBasicBlock &Else) { + return PymBranchInst(LLVMBuildCondBr(self.get(), If.get(), Then.get(), Else.get())); }, "If"_a, "Then"_a, "Else"_a) .def("switch", - [](PyBuilder &self, PyValue &value, PyBasicBlock &Else, + [](PymBuilder &self, PymValue &value, PymBasicBlock &Else, unsigned numCases) { - return PySwitchInst(LLVMBuildSwitch(self.get(), value.get(), Else.get(), numCases)); + return PymSwitchInst(LLVMBuildSwitch(self.get(), value.get(), Else.get(), numCases)); }, "value"_a, "Else"_a, "num_cases"_a) .def("indirect_br", - [](PyBuilder &self, PyValue &addr, unsigned numDests) { - return PyIndirectBrInst(LLVMBuildIndirectBr(self.get(), addr.get(), numDests)); + [](PymBuilder &self, PymValue &addr, unsigned numDests) { + return PymIndirectBrInst(LLVMBuildIndirectBr(self.get(), addr.get(), numDests)); }, "addr"_a, "num_dests"_a) .def("invoke", - [](PyBuilder &self, PyType &type, PyFunction &fn, std::vector args, - PyBasicBlock Then, PyBasicBlock Catch, const char *name) { + [](PymBuilder &self, PymType &type, PymFunction &fn, std::vector args, + PymBasicBlock Then, PymBasicBlock Catch, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); auto res = LLVMBuildInvoke2(self.get(), type.get(), fn.get(), rawArgs.data(), args_num, Then.get(), Catch.get(), name); - return PyInvokeInst(res); + return PymInvokeInst(res); }, "type"_a, "fn"_a, "args"_a, "Then"_a, "Catch"_a, "name"_a = "", "Original Function: LLVMBuildInvoke2.") .def("invoke_with_operand_bundles", - [](PyBuilder &self, PyType &type, PyFunction &fn, std::vector args, - PyBasicBlock Then, PyBasicBlock Catch, - std::vector bundles, const char *name) { + [](PymBuilder &self, PymType &type, PymFunction &fn, std::vector args, + PymBasicBlock Then, PymBasicBlock Catch, + std::vector bundles, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); @@ -446,62 +446,62 @@ void bindOtherClasses(nb::module_ &m) { rawArgs.data(), args_num, Then.get(), Catch.get(), rawBundles.data(), bundles_num, name); - return PyInvokeInst(res); + return PymInvokeInst(res); }, "type"_a, "fn"_a, "args"_a, "Then"_a, "Catch"_a, "bundles"_a, "name"_a = "") .def("unreachable", - [](PyBuilder &self) { - return PyInstruction(LLVMBuildUnreachable(self.get())); + [](PymBuilder &self) { + return PymInstruction(LLVMBuildUnreachable(self.get())); }) .def("resume", - [](PyBuilder &self, PyValue &exn) { - return PyInstruction(LLVMBuildResume(self.get(), exn.get())); + [](PymBuilder &self, PymValue &exn) { + return PymInstruction(LLVMBuildResume(self.get(), exn.get())); }, "exn"_a) .def("landing_pad", - [](PyBuilder &self, PyType &type, PyValue &PersFn, unsigned numClauses, + [](PymBuilder &self, PymType &type, PymValue &PersFn, unsigned numClauses, const char *name) { - return PyLandingPadInst(LLVMBuildLandingPad + return PymLandingPadInst(LLVMBuildLandingPad (self.get(), type.get(), PersFn.get(), numClauses, name)); }, "type"_a, "pers_fn"_a, "num_clauses"_a, "name"_a = "") .def("cleanup_ret", - [](PyBuilder &self, PyValue &catchPad, PyBasicBlock bb) { - return PyCleanupReturnInst(LLVMBuildCleanupRet(self.get(), catchPad.get(), + [](PymBuilder &self, PymValue &catchPad, PymBasicBlock bb) { + return PymCleanupReturnInst(LLVMBuildCleanupRet(self.get(), catchPad.get(), bb.get())); }, "catch_pad"_a, "bb"_a) .def("catch_pad", - [](PyBuilder &self, PyValue &parentPad, std::vector args, + [](PymBuilder &self, PymValue &parentPad, std::vector args, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); auto res = LLVMBuildCatchPad(self.get(), parentPad.get(), rawArgs.data(), args_num, name); - return PyCatchPadInst(res); + return PymCatchPadInst(res); }, "parent_pad"_a, "args"_a, "name"_a = "") .def("cleanup_pad", - [](PyBuilder &self, PyValue &parentPad, std::vector args, + [](PymBuilder &self, PymValue &parentPad, std::vector args, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); auto res = LLVMBuildCleanupPad(self.get(), parentPad.get(), rawArgs.data(), args_num, name); - return PyInstruction(res); + return PymInstruction(res); }, "parent_pad"_a, "args"_a, "name"_a = "") .def("catch_switch", - [](PyBuilder &self, PyValue &parentPad, PyBasicBlock &unwindBB, + [](PymBuilder &self, PymValue &parentPad, PymBasicBlock &unwindBB, unsigned numHandlers, const char *name) { auto res = LLVMBuildCatchSwitch(self.get(), parentPad.get(), unwindBB.get(), numHandlers, name); - return PyCatchSwitchInst(res); + return PymCatchSwitchInst(res); }, "parent_pad"_a, "unwind_bb"_a, "num_handlers"_a, "name"_a = "") /* @@ -509,180 +509,180 @@ void bindOtherClasses(nb::module_ &m) { */ BUILDER_BIND_BINARY_OPS .def("binop", - [](PyBuilder &self, LLVMOpcode op, PyValue &lhs, PyValue &rhs, + [](PymBuilder &self, LLVMOpcode op, PymValue &lhs, PymValue &rhs, const char *name) { - return PyValueAuto(LLVMBuildBinOp(self.get(), op, lhs.get(), rhs.get(), name)); + return PymValueAuto(LLVMBuildBinOp(self.get(), op, lhs.get(), rhs.get(), name)); }) .def("neg", - [](PyBuilder &self, PyValue &v, const char *name) { - return PyValueAuto(LLVMBuildNeg(self.get(), v.get(), name)); + [](PymBuilder &self, PymValue &v, const char *name) { + return PymValueAuto(LLVMBuildNeg(self.get(), v.get(), name)); }) .def("neg_nsw", - [](PyBuilder &self, PyValue &v, const char *name) { - return PyValueAuto(LLVMBuildNSWNeg(self.get(), v.get(), name)); + [](PymBuilder &self, PymValue &v, const char *name) { + return PymValueAuto(LLVMBuildNSWNeg(self.get(), v.get(), name)); }) .def("neg_nuw", - [](PyBuilder &self, PyValue &v, const char *name) { - return PyValueAuto(LLVMBuildNUWNeg(self.get(), v.get(), name)); + [](PymBuilder &self, PymValue &v, const char *name) { + return PymValueAuto(LLVMBuildNUWNeg(self.get(), v.get(), name)); }) .def("fneg", - [](PyBuilder &self, PyValue &v, const char *name) { - return PyValueAuto(LLVMBuildFNeg(self.get(), v.get(), name)); + [](PymBuilder &self, PymValue &v, const char *name) { + return PymValueAuto(LLVMBuildFNeg(self.get(), v.get(), name)); }) .def("not_", - [](PyBuilder &self, PyValue &v, const char *name) { - return PyValueAuto(LLVMBuildNot(self.get(), v.get(), name)); + [](PymBuilder &self, PymValue &v, const char *name) { + return PymValueAuto(LLVMBuildNot(self.get(), v.get(), name)); }) .def("malloc", - [](PyBuilder &self, PyType &type, const char *name) { - return PyCallInst(LLVMBuildMalloc(self.get(), type.get(), name)); + [](PymBuilder &self, PymType &type, const char *name) { + return PymCallInst(LLVMBuildMalloc(self.get(), type.get(), name)); }, "type"_a, "name"_a = "") .def("array_malloc", - [](PyBuilder &self, PyType &type, PyValue &val, const char *name) { - return PyCallInst(LLVMBuildArrayAlloca(self.get(), type.get(), val.get(), name)); + [](PymBuilder &self, PymType &type, PymValue &val, const char *name) { + return PymCallInst(LLVMBuildArrayAlloca(self.get(), type.get(), val.get(), name)); }, "type"_a, "value"_a, "name"_a = "") .def("memset", - [](PyBuilder &self, PyValue &ptr, PyValue &val, PyValue &len, unsigned align) { + [](PymBuilder &self, PymValue &ptr, PymValue &val, PymValue &len, unsigned align) { auto res = LLVMBuildMemSet(self.get(), ptr.get(), val.get(), len.get(), align); - return PyCallInst(res); + return PymCallInst(res); }, "ptr"_a, "val"_a, "len"_a, "align"_a) .def("memcpy", - [](PyBuilder &self, PyValue &dest, unsigned dstAlign, PyValue &src, - unsigned srcAlign, PyValue size) { + [](PymBuilder &self, PymValue &dest, unsigned dstAlign, PymValue &src, + unsigned srcAlign, PymValue size) { auto res = LLVMBuildMemCpy(self.get(), dest.get(), dstAlign, src.get(), srcAlign, size.get()); - return PyCallInst(res); + return PymCallInst(res); }, "dest"_a, "dest_align"_a, "src"_a, "src_align"_a, "size"_a, "Creates and inserts a memcpy between the specified pointers.") .def("mem_move", - [](PyBuilder &self, PyValue &dest, unsigned dstAlign, PyValue &src, - unsigned srcAlign, PyValue size) { + [](PymBuilder &self, PymValue &dest, unsigned dstAlign, PymValue &src, + unsigned srcAlign, PymValue size) { auto res = LLVMBuildMemMove(self.get(), dest.get(), dstAlign, src.get(), srcAlign, size.get()); - return PyCallInst(res); + return PymCallInst(res); }, "dest"_a, "dest_align"_a, "src"_a, "src_align"_a, "size"_a, "Creates and inserts a memmove between the specified pointers.") .def("alloca", - [](PyBuilder &self, PyType &type, const char *name) { - return PyAllocaInst(LLVMBuildAlloca(self.get(), type.get(), name)); + [](PymBuilder &self, PymType &type, const char *name) { + return PymAllocaInst(LLVMBuildAlloca(self.get(), type.get(), name)); }, "type"_a, "name"_a = "") .def("array_alloca", - [](PyBuilder &self, PyType &type, PyValue &val, const char *name) { - return PyAllocaInst(LLVMBuildArrayAlloca(self.get(), type.get(), + [](PymBuilder &self, PymType &type, PymValue &val, const char *name) { + return PymAllocaInst(LLVMBuildArrayAlloca(self.get(), type.get(), val.get(), name)); }, "type"_a, "value"_a, "name"_a = "") .def("free", - [](PyBuilder &self, PyValue pointer) { - return PyCallInst(LLVMBuildFree(self.get(), pointer.get())); + [](PymBuilder &self, PymValue pointer) { + return PymCallInst(LLVMBuildFree(self.get(), pointer.get())); }, "pointer"_a) .def("load2", - [](PyBuilder &self, PyType &type, PyValue &pointer, const char *name) { - return PyLoadInst(LLVMBuildLoad2(self.get(), type.get(), pointer.get(), + [](PymBuilder &self, PymType &type, PymValue &pointer, const char *name) { + return PymLoadInst(LLVMBuildLoad2(self.get(), type.get(), pointer.get(), name)); }, "type"_a, "ptr"_a, "name"_a = "") .def("store", - [](PyBuilder &self, PyValue &val, PyValue &ptr) { - return PyStoreInst(LLVMBuildStore(self.get(), val.get(), ptr.get())); + [](PymBuilder &self, PymValue &val, PymValue &ptr) { + return PymStoreInst(LLVMBuildStore(self.get(), val.get(), ptr.get())); }, "value"_a, "ptr"_a) .def("gep2", - [](PyBuilder &self, PyType &type, PyValue &ptr, std::vector indices, + [](PymBuilder &self, PymType &type, PymValue &ptr, std::vector indices, const char *name) { unsigned num_indices = indices.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, indices, rawIndices, num_indices); - return PyValueAuto(LLVMBuildGEP2(self.get(), type.get(), ptr.get(), + return PymValueAuto(LLVMBuildGEP2(self.get(), type.get(), ptr.get(), rawIndices.data(), num_indices, name)); }, "type"_a, "ptr"_a, "indices"_a, "name"_a = "") .def("in_bounds_gep2", - [](PyBuilder &self, PyType &type, PyValue &ptr, std::vector indices, + [](PymBuilder &self, PymType &type, PymValue &ptr, std::vector indices, const char *name) { unsigned num_indices = indices.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, indices, rawIndices, num_indices); - return PyValueAuto(LLVMBuildGEP2(self.get(), type.get(), ptr.get(), + return PymValueAuto(LLVMBuildGEP2(self.get(), type.get(), ptr.get(), rawIndices.data(), num_indices, name)); }, "type"_a, "ptr"_a, "indices"_a, "name"_a = "") .def("struct_gep2", - [](PyBuilder &self, PyType &type, PyValue &ptr, unsigned index, const char *name) { + [](PymBuilder &self, PymType &type, PymValue &ptr, unsigned index, const char *name) { auto res = LLVMBuildStructGEP2(self.get(), type.get(), ptr.get(), index, name); - return PyValueAuto(res); + return PymValueAuto(res); }, "type"_a, "ptr"_a, "index"_a, "name"_a = "") .def("global_string", - [](PyBuilder &self, const char *str, const char *name) { - return PyValueAuto(LLVMBuildGlobalString(self.get(), str, name)); + [](PymBuilder &self, const char *str, const char *name) { + return PymValueAuto(LLVMBuildGlobalString(self.get(), str, name)); }) .def("global_string_ptr", - [](PyBuilder &self, const char *str, const char *name) { - return PyValueAuto(LLVMBuildGlobalStringPtr(self.get(), str, name)); + [](PymBuilder &self, const char *str, const char *name) { + return PymValueAuto(LLVMBuildGlobalStringPtr(self.get(), str, name)); }) /* cast start */ BUILDER_BIND_CAST_OPS .def("cast", - [](PyBuilder &self, LLVMOpcode opcode, PyValue &value, PyType &destType, + [](PymBuilder &self, LLVMOpcode opcode, PymValue &value, PymType &destType, const char *name) { - return PyValueAuto(LLVMBuildCast(self.get(), opcode, value.get(), + return PymValueAuto(LLVMBuildCast(self.get(), opcode, value.get(), destType.get(), name)); }, "opcode"_a, "value"_a, "dest_type"_a, "name"_a = "") .def("int_cast_2", - [](PyBuilder &self, PyValue &value, PyType &destType, const char *name){ - return PyValueAuto(LLVMBuildFPCast + [](PymBuilder &self, PymValue &value, PymType &destType, const char *name){ + return PymValueAuto(LLVMBuildFPCast (self.get(), value.get(), destType.get(), name)); }, "value"_a, "dest_type"_a, "name"_a = "") .def("int_cast", - [](PyBuilder &self, PyValue &value, PyType &destType, const char *name){ - return PyValueAuto(LLVMBuildIntCast + [](PymBuilder &self, PymValue &value, PymType &destType, const char *name){ + return PymValueAuto(LLVMBuildIntCast (self.get(), value.get(), destType.get(), name)); }, "value"_a, "dest_type"_a, "name"_a = "", "Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead.") .def_static("get_cast_opcode", - [](PyValue &src, bool srcIsSigned, PyType &destType, bool destIsSigned) { + [](PymValue &src, bool srcIsSigned, PymType &destType, bool destIsSigned) { return LLVMGetCastOpcode(src.get(), srcIsSigned, destType.get(), destIsSigned); }, "src"_a, "src_is_signed"_a, "dest_type"_a, "dest_is_signed"_a) /* end */ .def("icmp", - [](PyBuilder &self, LLVMIntPredicate op, PyValue &lhs, PyValue &rhs, + [](PymBuilder &self, LLVMIntPredicate op, PymValue &lhs, PymValue &rhs, const char *name) { - return PyValueAuto(LLVMBuildICmp(self.get(), op, lhs.get(), rhs.get(), + return PymValueAuto(LLVMBuildICmp(self.get(), op, lhs.get(), rhs.get(), name)); }, "op"_a, "lhs"_a, "rhs"_a, "name"_a = "") .def("phi", - [](PyBuilder &self, PyType &type, const char *name) { - return PyPHINode(LLVMBuildPhi(self.get(), type.get(), name)); + [](PymBuilder &self, PymType &type, const char *name) { + return PymPHINode(LLVMBuildPhi(self.get(), type.get(), name)); }, "type"_a, "name"_a = "") .def("call_2", - [](PyBuilder &self, PyTypeFunction &type, PyFunction &fn, std::vector args, + [](PymBuilder &self, PymTypeFunction &type, PymFunction &fn, std::vector args, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); - return PyCallInst(LLVMBuildCall2 + return PymCallInst(LLVMBuildCall2 (self.get(), type.get(), fn.get(), rawArgs.data(), args_num, name)); }, "fn_type"_a, "fn"_a, "args"_a, "name"_a = "") .def("call_with_operand_bundles", - [](PyBuilder &self, PyTypeFunction type, PyFunction fn, - std::vector args, - std::vector bundles, + [](PymBuilder &self, PymTypeFunction type, PymFunction fn, + std::vector args, + std::vector bundles, const char *name) { unsigned args_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, rawArgs, args_num); @@ -691,133 +691,133 @@ void bindOtherClasses(nb::module_ &m) { UNWRAP_VECTOR_WRAPPER_CLASS(LLVMOperandBundleRef, bundles, rawBundles, bundles_num); - return PyCallInst(LLVMBuildCallWithOperandBundles + return PymCallInst(LLVMBuildCallWithOperandBundles (self.get(), type.get(), fn.get(), rawArgs.data(), args_num, rawBundles.data(), bundles_num, name)); }) .def("select", - [](PyBuilder &self, PyValue &If, PyValue &Then, PyValue &Else, + [](PymBuilder &self, PymValue &If, PymValue &Then, PymValue &Else, const char *name) { - return PyCallInst(LLVMBuildSelect + return PymCallInst(LLVMBuildSelect (self.get(), If.get(), Then.get(), Else.get(), name)); }, "If"_a, "Then"_a, "Else"_a, "name"_a = "") .def("vaarg", - [](PyBuilder &self, PyValue &list, PyType &type, const char *name) { - return PyValue(LLVMBuildVAArg(self.get(), list.get(), type.get(), + [](PymBuilder &self, PymValue &list, PymType &type, const char *name) { + return PymValue(LLVMBuildVAArg(self.get(), list.get(), type.get(), name)); }, "list"_a, "type"_a, "name"_a = "") .def("extract_element", - [](PyBuilder &self, PyValue &vecVal, PyValue &index, const char *name) { - return PyValueAuto(LLVMBuildExtractElement + [](PymBuilder &self, PymValue &vecVal, PymValue &index, const char *name) { + return PymValueAuto(LLVMBuildExtractElement (self.get(), vecVal.get(), index.get(), name)); }, "vec"_a, "index"_a, "name"_a = "") .def("insert_element", - [](PyBuilder &self, PyValue &vecVal, PyValue &eltVal, - PyValue &index, const char *name) { - return PyValueAuto(LLVMBuildInsertElement + [](PymBuilder &self, PymValue &vecVal, PymValue &eltVal, + PymValue &index, const char *name) { + return PymValueAuto(LLVMBuildInsertElement (self.get(), vecVal.get(), eltVal.get(), index.get(), name)); }, "vec"_a, "element"_a, "index"_a, "name"_a = "") .def("shuffle_vector", - [](PyBuilder &self, PyValue &v1, PyValue &v2, PyValue &mask, const char *name) { - return PyShuffleVectorInst(LLVMBuildShuffleVector + [](PymBuilder &self, PymValue &v1, PymValue &v2, PymValue &mask, const char *name) { + return PymShuffleVectorInst(LLVMBuildShuffleVector (self.get(), v1.get(), v2.get(), mask.get(), name)); }, "v1"_a, "v2"_a, "mask"_a, "name"_a = "") .def("extract_value", - [](PyBuilder &self, PyValue &aggVal, unsigned index, const char *name) { - return PyValueAuto(LLVMBuildExtractValue + [](PymBuilder &self, PymValue &aggVal, unsigned index, const char *name) { + return PymValueAuto(LLVMBuildExtractValue (self.get(), aggVal.get(), index, name)); }, "agg"_a, "index"_a, "name"_a = "") .def("insert_value", - [](PyBuilder &self, PyValue &aggVal, PyValue &eltVal, unsigned index, + [](PymBuilder &self, PymValue &aggVal, PymValue &eltVal, unsigned index, const char *name) { - return PyValueAuto(LLVMBuildInsertValue + return PymValueAuto(LLVMBuildInsertValue (self.get(), aggVal.get(), eltVal.get(), index, name)); }, "agg"_a, "elt"_a, "index"_a, "name"_a = "") .def("freeze", - [](PyBuilder &self, PyValue &val, const char *name) { - return PyValueAuto(LLVMBuildFreeze(self.get(), val.get(), name)); + [](PymBuilder &self, PymValue &val, const char *name) { + return PymValueAuto(LLVMBuildFreeze(self.get(), val.get(), name)); }, "val"_a, "name"_a = "") .def("is_null", - [](PyBuilder &self, PyValue &val, const char *name) { - return PyValueAuto(LLVMBuildIsNull(self.get(), val.get(), name)); + [](PymBuilder &self, PymValue &val, const char *name) { + return PymValueAuto(LLVMBuildIsNull(self.get(), val.get(), name)); }, "value"_a, "name"_a = "") .def("is_not_null", - [](PyBuilder &self, PyValue &val, const char *name) { - return PyValueAuto(LLVMBuildIsNotNull(self.get(), val.get(), name)); + [](PymBuilder &self, PymValue &val, const char *name) { + return PymValueAuto(LLVMBuildIsNotNull(self.get(), val.get(), name)); }, "value"_a, "name"_a = "") .def("ptr_diff_2", - [](PyBuilder &self, PyType &elemType, PyValue &lhs, PyValue &rhs, + [](PymBuilder &self, PymType &elemType, PymValue &lhs, PymValue &rhs, const char *name) { - return PyValueAuto(LLVMBuildPtrDiff2 + return PymValueAuto(LLVMBuildPtrDiff2 (self.get(), elemType.get(), lhs.get(), rhs.get(), name)); }, "elem_type"_a, "lhs"_a, "rhs"_a, "name"_a = "") .def("fence", - [](PyBuilder &self, LLVMAtomicOrdering ordering, bool singleThread, + [](PymBuilder &self, LLVMAtomicOrdering ordering, bool singleThread, const char *name) { - return PyFenceInst(LLVMBuildFence(self.get(), ordering, singleThread, name)); + return PymFenceInst(LLVMBuildFence(self.get(), ordering, singleThread, name)); }, "ordering"_a, "singleThread"_a, "name"_a = "") .def("atomic_rmw", - [](PyBuilder &self, LLVMAtomicRMWBinOp op, PyValue &ptr, PyValue val, + [](PymBuilder &self, LLVMAtomicRMWBinOp op, PymValue &ptr, PymValue val, LLVMAtomicOrdering ordering, bool singleThread) { auto res = LLVMBuildAtomicRMW(self.get(), op, ptr.get(), val.get(), ordering, singleThread); - return PyAtomicRMWInst(res); + return PymAtomicRMWInst(res); }, "op"_a, "ptr"_a, "val"_a, "ordering"_a, "singleThread"_a) .def("atomic_cmp_xchg", - [](PyBuilder &self, PyValue &ptr, PyValue &cmp, PyValue &New, + [](PymBuilder &self, PymValue &ptr, PymValue &cmp, PymValue &New, LLVMAtomicOrdering successOrdering, LLVMAtomicOrdering failureOrdering, bool singleThread) { auto res = LLVMBuildAtomicCmpXchg(self.get(), ptr.get(), cmp.get(), New.get(), successOrdering, failureOrdering, singleThread); - return PyAtomicCmpXchgInst(res); + return PymAtomicCmpXchgInst(res); }); BasicBlockClass .def("__repr__", - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { return ""; }) .def("__str__", - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { auto value = LLVMBasicBlockAsValue(self.get()); return get_value_str(value); }) .def("__init__", - [](PyBasicBlock *bb, PyContext &c, const char *name) { - new (bb) PyBasicBlock(LLVMCreateBasicBlockInContext(c.get(), name)); + [](PymBasicBlock *bb, PymContext &c, const char *name) { + new (bb) PymBasicBlock(LLVMCreateBasicBlockInContext(c.get(), name)); }, "context"_a, "name"_a = "", "Create a new basic block without inserting it into a function.") .def("__init__", - [](PyBasicBlock *bb, PyContext &c, PyFunction &f, const char *name) { - new (bb) PyBasicBlock(LLVMAppendBasicBlockInContext + [](PymBasicBlock *bb, PymContext &c, PymFunction &f, const char *name) { + new (bb) PymBasicBlock(LLVMAppendBasicBlockInContext (c.get(), f.get(), name)); }, "context"_a, "function"_a, "name"_a = "", "Create a new basic block without inserting it into a function.") .def("__init__", - [](PyBasicBlock *bb, PyContext &c, PyBasicBlock &BB, const char *name) { - new (bb) PyBasicBlock(LLVMInsertBasicBlockInContext + [](PymBasicBlock *bb, PymContext &c, PymBasicBlock &BB, const char *name) { + new (bb) PymBasicBlock(LLVMInsertBasicBlockInContext (c.get(), BB.get(), name)); }, "context"_a, "bb"_a, "name"_a = "", @@ -825,84 +825,84 @@ void bindOtherClasses(nb::module_ &m) { "The function to add to is determined by the function of the" "passed basic block.") .def("__init__", - [](PyBasicBlock *bb, PyBasicBlock &BB, const char *name) { - new (bb) PyBasicBlock(LLVMInsertBasicBlock(BB.get(), name)); + [](PymBasicBlock *bb, PymBasicBlock &BB, const char *name) { + new (bb) PymBasicBlock(LLVMInsertBasicBlock(BB.get(), name)); }, "insert_before_bb"_a, "name"_a = "", "Insert a basic block in a function using the global context.") .def_prop_ro("name", - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { return LLVMGetBasicBlockName(self.get()); }) .def_prop_ro("parent", - [](PyBasicBlock &self) { - return PyFunction(LLVMGetBasicBlockParent(self.get())); + [](PymBasicBlock &self) { + return PymFunction(LLVMGetBasicBlockParent(self.get())); }, "Obtain the function to which a basic block belongs.") .def_prop_ro("terminator", - [](PyBasicBlock &self) -> optional { + [](PymBasicBlock &self) -> optional { auto res = LLVMGetBasicBlockTerminator(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstruction); + WRAP_OPTIONAL_RETURN(res, PymInstruction); }, "Obtain the terminator instruction for a basic block.\n\n" "If the basic block does not have a terminator (it is not well-formed" "if it doesn't), then NULL is returned.") .def_prop_ro("value", - [](PyBasicBlock &self) { - return PyBasicBlockValue(LLVMBasicBlockAsValue(self.get())); + [](PymBasicBlock &self) { + return PymBasicBlockValue(LLVMBasicBlockAsValue(self.get())); }) .def_prop_ro("next", - [](PyBasicBlock &self) -> optional { + [](PymBasicBlock &self) -> optional { auto res = LLVMGetNextBasicBlock(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlock); + WRAP_OPTIONAL_RETURN(res, PymBasicBlock); }) .def_prop_ro("prev", - [](PyBasicBlock &self) -> optional { + [](PymBasicBlock &self) -> optional { auto res = LLVMGetPreviousBasicBlock(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlock); + WRAP_OPTIONAL_RETURN(res, PymBasicBlock); }) .def_prop_ro("first_instruction", - [](PyBasicBlock &self) -> optional { + [](PymBasicBlock &self) -> optional { auto res = LLVMGetFirstInstruction(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstruction); + WRAP_OPTIONAL_RETURN(res, PymInstruction); }) .def_prop_ro("last_instruction", - [](PyBasicBlock &self) -> optional { + [](PymBasicBlock &self) -> optional { auto res = LLVMGetLastInstruction(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstruction); + WRAP_OPTIONAL_RETURN(res, PymInstruction); }) .def_prop_ro("instructions", - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { auto res = LLVMGetFirstInstruction(self.get()); - return PyInstructionIterator(PyInstruction(res)); + return PymInstructionIterator(PymInstruction(res)); }) .def("create_and_insert_before", - [](PyBasicBlock &self, const char *name) { - return PyBasicBlock(LLVMInsertBasicBlock(self.get(), name)); + [](PymBasicBlock &self, const char *name) { + return PymBasicBlock(LLVMInsertBasicBlock(self.get(), name)); }, "Insert a basic block in a function using the global context.") .def("destroy", // TODO test - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { return LLVMDeleteBasicBlock(self.get()); }, "Remove a basic block from a function and delete it.\n\n" "This deletes the basic block from its containing function and deletes" "the basic block itself.") .def("remove_from_parent", - [](PyBasicBlock &self) { + [](PymBasicBlock &self) { return LLVMRemoveBasicBlockFromParent(self.get()); }, "Remove a basic block from a function.\n\n" "This deletes the basic block from its containing function but keep" "the basic block alive.") .def("move_before", - [](PyBasicBlock &self, PyBasicBlock posBB) { + [](PymBasicBlock &self, PymBasicBlock posBB) { return LLVMMoveBasicBlockBefore(self.get(), posBB.get()); }, "pos"_a, "Move a basic block to before another one.") .def("move_after", - [](PyBasicBlock &self, PyBasicBlock posBB) { + [](PymBasicBlock &self, PymBasicBlock posBB) { return LLVMMoveBasicBlockAfter(self.get(), posBB.get()); }, "pos", @@ -911,59 +911,59 @@ void bindOtherClasses(nb::module_ &m) { OperandBundleClass .def("__repr__", - [](PyOperandBundle &self) { + [](PymOperandBundle &self) { return ""; }) .def("__init__", - [](PyOperandBundle *ob, std::string &tag, std::vector args) { + [](PymOperandBundle *ob, std::string &tag, std::vector args) { unsigned arg_num = args.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, args, raw_args, arg_num); - new (ob) PyOperandBundle(LLVMCreateOperandBundle + new (ob) PymOperandBundle(LLVMCreateOperandBundle (tag.c_str(), tag.size(), raw_args.data(), arg_num)); }) .def_prop_ro("tag", - [](PyOperandBundle &self) { + [](PymOperandBundle &self) { size_t len; auto tag = LLVMGetOperandBundleTag(self.get(), &len); return std::string(tag, len); }) .def_prop_ro("operands_num", - [](PyOperandBundle &self) { + [](PymOperandBundle &self) { return LLVMGetNumOperandBundleArgs(self.get()); }) .def("get_operand_at", - [](PyOperandBundle &self, unsigned index) { - return PyValueAuto(LLVMGetOperandBundleArgAtIndex(self.get(), index)); + [](PymOperandBundle &self, unsigned index) { + return PymValueAuto(LLVMGetOperandBundleArgAtIndex(self.get(), index)); }); IntrinsicClass .def("__repr__", - [](PyIntrinsic &self) { + [](PymIntrinsic &self) { return ""; }) .def("__repr__", - [](PyIntrinsic &self) { + [](PymIntrinsic &self) { size_t len; auto raw_name = LLVMIntrinsicGetName(self.get(), &len); auto name = std::string(raw_name, len); return fmt::format("", self.get(), name); }) .def("__bool__", // override default behavior - [](PyIntrinsic &self) { return true; }) + [](PymIntrinsic &self) { return true; }) .def_static("lookup", [](std::string &name) { - return PyIntrinsic(LLVMLookupIntrinsicID(name.c_str(), name.size())); + return PymIntrinsic(LLVMLookupIntrinsicID(name.c_str(), name.size())); }, "name"_a = "", "Obtain the intrinsic ID number which matches the given function name.") .def("get_type", - [](PyIntrinsic &self, PyContext &context, std::vector paramTypes) { + [](PymIntrinsic &self, PymContext &context, std::vector paramTypes) { size_t paramCnt = paramTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, paramTypes, params, paramCnt); - return PyTypeFunction(LLVMIntrinsicGetType + return PymTypeFunction(LLVMIntrinsicGetType (context.get(), self.get(), params.data(), paramCnt)); @@ -972,23 +972,23 @@ void bindOtherClasses(nb::module_ &m) { "Retrieves the type of an intrinsic. For overloaded intrinsics," " parameter types must be provided to uniquely identify an overload.") .def_prop_ro("id", - [](PyIntrinsic &self) { + [](PymIntrinsic &self) { return self.get(); }) .def_prop_ro("name", - [](PyIntrinsic &self) { + [](PymIntrinsic &self) { size_t len; auto name = LLVMIntrinsicGetName(self.get(), &len); return std::string(name, len); }, "Retrieves the name of an intrinsic.") .def_prop_ro("is_overloaded", - [](PyIntrinsic &self) { + [](PymIntrinsic &self) { return LLVMIntrinsicIsOverloaded(self.get()) != 0; }) // note LLVMIntrinsicCopyOverloadedName is deprecated .def("copy_overloaded_name", - [](PyIntrinsic &self, std::vector paramTypes) { + [](PymIntrinsic &self, std::vector paramTypes) { size_t paramCnt = paramTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, paramTypes, params, paramCnt); size_t nameLen; @@ -999,7 +999,7 @@ void bindOtherClasses(nb::module_ &m) { "param_types"_a, "Deprecated: Use :func:`copy_overloaded_name2` instead.") .def("copy_overloaded_name2", - [](PyIntrinsic &self, PyModule &module, std::vector paramTypes) { + [](PymIntrinsic &self, PymModule &module, std::vector paramTypes) { size_t nameLen; size_t paramCnt = paramTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, paramTypes, params, paramCnt); @@ -1016,18 +1016,18 @@ void bindOtherClasses(nb::module_ &m) { MetadataEntriesClass .def("__repr__", - [](PyMetadataEntries &self) { + [](PymMetadataEntries &self) { return ""; }) .def("get_kind", - [](PyMetadataEntries &self, unsigned index) { + [](PymMetadataEntries &self, unsigned index) { return LLVMValueMetadataEntriesGetKind(self.get(), index); }, "index"_a, "Returns the kind of a value metadata entry at a specific index.") .def("get_metadata", - [](PyMetadataEntries &self, unsigned index) { - return PyMetadata(LLVMValueMetadataEntriesGetMetadata(self.get(), index)); + [](PymMetadataEntries &self, unsigned index) { + return PymMetadata(LLVMValueMetadataEntriesGetMetadata(self.get(), index)); }, "index"_a, "Returns the underlying metadata node of a value metadata entry at a" @@ -1035,67 +1035,67 @@ void bindOtherClasses(nb::module_ &m) { UseClass .def("__repr__", - [](PyUse &self) { + [](PymUse &self) { return ""; }) .def_prop_ro("next", - [](PyUse &u) -> optional { + [](PymUse &u) -> optional { auto res = LLVMGetNextUse(u.get()); - WRAP_OPTIONAL_RETURN(res, PyUse); + WRAP_OPTIONAL_RETURN(res, PymUse); }, "Obtain the next use of a value.\n\n" "This effectively advances the iterator. It returns NULL if you are on" "the final use and no more are available.") .def_prop_ro("user", - [](PyUse &u) { return PyUser(LLVMGetUser(u.get())); }, + [](PymUse &u) { return PymUser(LLVMGetUser(u.get())); }, "Obtain the user value for a user.\n", "The returned value corresponds to a llvm::User type.") .def_prop_ro("used_value", - [](PyUse &u) { - return PyValueAuto(LLVMGetUsedValue(u.get())); + [](PymUse &u) { + return PymValueAuto(LLVMGetUsedValue(u.get())); }); AttributeClass .def("__repr__", - [](PyAttribute &self) { + [](PymAttribute &self) { return ""; }) .def_prop_ro("is_enum", - [](PyAttribute &attr) { + [](PymAttribute &attr) { return LLVMIsEnumAttribute(attr.get()) != 0; }) .def_prop_ro("is_string", - [](PyAttribute &attr) { + [](PymAttribute &attr) { return LLVMIsStringAttribute(attr.get()) != 0; }) .def_prop_ro("is_type", - [](PyAttribute &attr) { + [](PymAttribute &attr) { return LLVMIsTypeAttribute(attr.get()) != 0; }); EnumAttributeClass .def("__repr__", - [](PyEnumAttribute &self) { + [](PymEnumAttribute &self) { return ""; }) .def("__init__", - [](PyEnumAttribute *t, PyContext &c, unsigned kindID, uint64_t val) { - new (t) PyEnumAttribute(LLVMCreateEnumAttribute(c.get(), kindID, val)); + [](PymEnumAttribute *t, PymContext &c, unsigned kindID, uint64_t val) { + new (t) PymEnumAttribute(LLVMCreateEnumAttribute(c.get(), kindID, val)); }, "context"_a, "kind_id"_a, "val"_a) .def("__repr__", - [](PyEnumAttribute &self) { + [](PymEnumAttribute &self) { auto kind = LLVMGetEnumAttributeKind(self.get()); auto value = LLVMGetEnumAttributeValue(self.get()); return fmt::format("", kind, value); }) .def_prop_ro("kind", - [](PyEnumAttribute &attr) { + [](PymEnumAttribute &attr) { return LLVMGetEnumAttributeKind(attr.get()); }, "attr"_a) .def_prop_ro("value", - [](PyEnumAttribute &attr) { + [](PymEnumAttribute &attr) { return LLVMGetEnumAttributeValue(attr.get()); }, "Get the enum attribute's value. 0 is returned if none exists.") @@ -1115,42 +1115,42 @@ void bindOtherClasses(nb::module_ &m) { TypeAttributeClass .def("__repr__", - [](PyTypeAttribute &self) { + [](PymTypeAttribute &self) { return ""; }) .def("__init__", - [](PyTypeAttribute *t, PyContext &context, unsigned kind_id, PyType &type) { - new (t) PyTypeAttribute(LLVMCreateTypeAttribute + [](PymTypeAttribute *t, PymContext &context, unsigned kind_id, PymType &type) { + new (t) PymTypeAttribute(LLVMCreateTypeAttribute (context.get(), kind_id, type.get())); }, "context"_a, "kind_id"_a, "type"_a) .def("__repr__", - [](PyTypeAttribute &self) { + [](PymTypeAttribute &self) { auto value = LLVMGetTypeAttributeValue(self.get()); auto type_kind = LLVMGetTypeKind(value); return fmt::format("", get_repr_str(type_kind)); }) .def_prop_ro("value", - [](PyTypeAttribute &ta){ - return PyTypeAuto(LLVMGetTypeAttributeValue(ta.get())); + [](PymTypeAttribute &ta){ + return PymTypeAuto(LLVMGetTypeAttributeValue(ta.get())); }, "Get the type attribute's value."); StringAttributeClass .def("__repr__", - [](PyStringAttribute &self) { + [](PymStringAttribute &self) { return ""; }) .def("__init__", - [](PyStringAttribute *t, PyContext &c, const std::string &kind, const std::string &value) { + [](PymStringAttribute *t, PymContext &c, const std::string &kind, const std::string &value) { auto raw = LLVMCreateStringAttribute(c.get(), kind.c_str(), kind.size(), value.c_str(), value.size()); - new (t) PyStringAttribute(raw); + new (t) PymStringAttribute(raw); }, "context"_a, "kind"_a, "value"_a) .def("__repr__", - [](PyStringAttribute &self) { + [](PymStringAttribute &self) { unsigned kind_length; const char *raw_kind = LLVMGetStringAttributeKind(self.get(), &kind_length); auto kind = std::string(raw_kind, kind_length); @@ -1162,13 +1162,13 @@ void bindOtherClasses(nb::module_ &m) { return fmt::format("", kind, value); }) .def_prop_ro("kind", - [](PyStringAttribute &ta) { + [](PymStringAttribute &ta) { unsigned length; const char *kind = LLVMGetStringAttributeKind(ta.get(), &length); return std::string(kind, length); }) .def_prop_ro("value", - [](PyStringAttribute &ta) { + [](PymStringAttribute &ta) { unsigned length; const char *value = LLVMGetStringAttributeValue(ta.get(), &length); return std::string(value, length); @@ -1178,12 +1178,12 @@ void bindOtherClasses(nb::module_ &m) { DiagnosticInfoClass .def("__repr__", - [](PyDiagnosticInfo &self) { + [](PymDiagnosticInfo &self) { return ""; }) // .def(nb::init<>()) // NOTE currently no constructor function for python, we'll see .def_prop_ro("description", - [](PyDiagnosticInfo &d) { + [](PymDiagnosticInfo &d) { char *diagInfoDesc = LLVMGetDiagInfoDescription(d.get()); std::string diagInfoDescCopy(diagInfoDesc); LLVMDisposeMessage(diagInfoDesc); @@ -1191,7 +1191,7 @@ void bindOtherClasses(nb::module_ &m) { }, "Return a string representation of the DiagnosticInfo.") .def_prop_ro("severity", - [](PyDiagnosticInfo &d) { + [](PymDiagnosticInfo &d) { return LLVMGetDiagInfoSeverity(d.get()); }, "Return an enum LLVMDiagnosticSeverity."); @@ -1199,27 +1199,27 @@ void bindOtherClasses(nb::module_ &m) { NamedMDNodeClass .def("__repr__", - [](PyNamedMDNode &self) { + [](PymNamedMDNode &self) { return ""; }) .def_prop_ro("next", - [](PyNamedMDNode &nmdn) -> optional{ + [](PymNamedMDNode &nmdn) -> optional{ auto res = LLVMGetNextNamedMetadata(nmdn.get()); - WRAP_OPTIONAL_RETURN(res, PyNamedMDNode); + WRAP_OPTIONAL_RETURN(res, PymNamedMDNode); }, "Advance a NamedMDNode iterator to the next NamedMDNode.\n\n" "Returns NULL if the iterator was already at the end and there" " are no more named metadata nodes.") .def_prop_ro("prev", - [](PyNamedMDNode &nmdn) -> optional { + [](PymNamedMDNode &nmdn) -> optional { auto res = LLVMGetPreviousNamedMetadata(nmdn.get()); - WRAP_OPTIONAL_RETURN(res, PyNamedMDNode); + WRAP_OPTIONAL_RETURN(res, PymNamedMDNode); }, "Decrement a NamedMDNode iterator to the previous NamedMDNode.\n\n" "Returns NULL if the iterator was already at the beginning and there are" "no previous named metadata nodes.") .def_prop_ro("name", - [](PyNamedMDNode &nmdn) { + [](PymNamedMDNode &nmdn) { size_t len; const char *name = LLVMGetNamedMetadataName(nmdn.get(), &len); return std::string(name, len); @@ -1229,20 +1229,20 @@ void bindOtherClasses(nb::module_ &m) { ContextClass .def("__repr__", - [](PyContext &self) { + [](PymContext &self) { return ""; }) .def(nb::init<>(), "Create a new context.") .def("__enter__", - [](PyContext &self) { + [](PymContext &self) { return &self; }) .def("__exit__", - [](PyContext &self, nb::args args, nb::kwargs kwargs) {}) - .def_static("get_global_context", &PyContext::getGlobalContext, + [](PymContext &self, nb::args args, nb::kwargs kwargs) {}) + .def_static("get_global_context", &PymContext::getGlobalContext, "Obtain the global context instance.") .def_prop_ro("diagnostic_context", - [](PyContext &c) { + [](PymContext &c) { // FIXME The function cannot work correctly (always None) since // `LLVMContextSetDiagnosticHandler` cannot, which set // the diagnostic context @@ -1250,8 +1250,8 @@ void bindOtherClasses(nb::module_ &m) { }, "Get the diagnostic context of this context.") .def_prop_rw("should_discard_value_names", // TODO convert LLVMBool to bool - [](PyContext &c) -> bool { return LLVMContextShouldDiscardValueNames(c.get()) != 0; }, - [](PyContext &c, bool discard) { + [](PymContext &c) -> bool { return LLVMContextShouldDiscardValueNames(c.get()) != 0; }, + [](PymContext &c, bool discard) { return LLVMContextSetDiscardValueNames(c.get(), discard); }, nb::for_getter @@ -1267,22 +1267,22 @@ void bindOtherClasses(nb::module_ &m) { "This can be used to save memory and runtime, " "especially in release mode.")) .def("set_diagnostic_handler", // FIXME - [](PyContext &c, LLVMDiagnosticHandler handler, void * diagnosticContext){ + [](PymContext &c, LLVMDiagnosticHandler handler, void * diagnosticContext){ return LLVMContextSetDiagnosticHandler(c.get(), handler, diagnosticContext); }, "handler"_a, "diagnostic_context"_a, "Set the diagnostic handler for this context.") // .def("get_diagnostic_handler", FIXME - // [](PyContext &c) { return LLVMContextGetDiagnosticHandler(c.get()); }, + // [](PymContext &c) { return LLVMContextGetDiagnosticHandler(c.get()); }, // "Get the diagnostic handler of this context.") .def("set_yield_callback", // FIXME - [](PyContext &c, LLVMYieldCallback callback, void *opaqueHandle){ + [](PymContext &c, LLVMYieldCallback callback, void *opaqueHandle){ return LLVMContextSetYieldCallback(c.get(), callback, opaqueHandle); }, "callback"_a, "opaque_handle"_a, "Set the yield callback function for this context.") .def("parse_ir", - [](PyContext &self, PyMemoryBuffer &memBuf) { + [](PymContext &self, PymMemoryBuffer &memBuf) { try { auto res = parseIR(self.get(), memBuf.get()); memBuf.reset(); // We Cannot reuse the memory buffer again @@ -1298,26 +1298,26 @@ void bindOtherClasses(nb::module_ &m) { ":raises RuntimeError\n" "NOTE that you cannot use passed-in memory_buffer after this operation.") .def("create_builder", - [](PyContext &self) { - return PyBuilder(LLVMCreateBuilderInContext(self.get())); + [](PymContext &self) { + return PymBuilder(LLVMCreateBuilderInContext(self.get())); }) .def("create_basic_block", - [](PyContext &self, const char *name) { - return PyBasicBlock(LLVMCreateBasicBlockInContext + [](PymContext &self, const char *name) { + return PymBasicBlock(LLVMCreateBasicBlockInContext (self.get(), name)); }, "name"_a = "", "Create a new basic block without inserting it into a function.") .def("append_basic_block", - [](PyContext &self, PyFunction fn, const char *name) { - return PyBasicBlock(LLVMAppendBasicBlockInContext + [](PymContext &self, PymFunction fn, const char *name) { + return PymBasicBlock(LLVMAppendBasicBlockInContext (self.get(), fn.get(), name)); }, "fn"_a, "name"_a = "", "Append a basic block to the end of a function.") .def("insert_basic_block", - [](PyContext &self, PyBasicBlock bb, const char *name) { - return PyBasicBlock(LLVMInsertBasicBlockInContext + [](PymContext &self, PymBasicBlock bb, const char *name) { + return PymBasicBlock(LLVMInsertBasicBlockInContext (self.get(), bb.get(), name)); }, "bb"_a, "name"_a = "", @@ -1325,51 +1325,51 @@ void bindOtherClasses(nb::module_ &m) { "The function to add to is determined by the function of the" "passed basic block.") .def("get_md_kind_id", - [](PyContext &c, const std::string &name) { + [](PymContext &c, const std::string &name) { return LLVMGetMDKindIDInContext(c.get(), name.c_str(), name.size()); }, "name"_a = "") .def("create_enum_attribute", - [](PyContext &c, unsigned kindID, uint64_t val) { - return PyEnumAttribute(LLVMCreateEnumAttribute(c.get(), kindID, val)); + [](PymContext &c, unsigned kindID, uint64_t val) { + return PymEnumAttribute(LLVMCreateEnumAttribute(c.get(), kindID, val)); }, "kind_id"_a, "val"_a, "Create an enum attribute.") .def("create_type_attribute", - [](PyContext &context, unsigned kind_id, PyType &type) { - return PyTypeAttribute(LLVMCreateTypeAttribute + [](PymContext &context, unsigned kind_id, PymType &type) { + return PymTypeAttribute(LLVMCreateTypeAttribute (context.get(), kind_id, type.get())); }, "kind_id"_a, "type"_a, "Create a type attribute") .def("create_string_attribute", - [](PyContext &c, const std::string &kind, const std::string &value) { + [](PymContext &c, const std::string &kind, const std::string &value) { auto raw = LLVMCreateStringAttribute(c.get(), kind.c_str(), kind.size(), value.c_str(), value.size()); - return PyStringAttribute(raw); + return PymStringAttribute(raw); }) - .def("get_type_by_name_2", // TODO also create one in PyType static method - [](PyContext &c, const char *name) -> optional { + .def("get_type_by_name_2", // TODO also create one in PymType static method + [](PymContext &c, const char *name) -> optional { auto res = LLVMGetTypeByName2(c.get(), name); - WRAP_OPTIONAL_RETURN(res, PyTypeAuto); + WRAP_OPTIONAL_RETURN(res, PymTypeAuto); }, "name"_a = "") .def("create_md_string_2", - [](PyContext &self, std::string &name) { - return PyMDString(LLVMMDStringInContext2(self.get(), name.c_str(), name.size())); + [](PymContext &self, std::string &name) { + return PymMDString(LLVMMDStringInContext2(self.get(), name.c_str(), name.size())); }, "name"_a = "", "Create an MDString value from a given string value.") .def("create_md_node_2", - [](PyContext &self, std::vector mds) { + [](PymContext &self, std::vector mds) { size_t num = mds.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMMetadataRef, mds, raw, num); - return PyMDNode(LLVMMDNodeInContext2(self.get(), raw.data(), num)); + return PymMDNode(LLVMMDNodeInContext2(self.get(), raw.data(), num)); }, "metadata"_a) .def("get_metadata_as_value", - [](PyContext &self, PyMetadata &md) { + [](PymContext &self, PymMetadata &md) { return getMoreSpcMetadataAsValue(LLVMMetadataAsValue (self.get(), md.get())); }); @@ -1379,14 +1379,14 @@ void bindOtherClasses(nb::module_ &m) { ModuleClass .def(nb::init(), "name"_a = "") .def("__repr__", - [](PyModule &self) { + [](PymModule &self) { size_t len; const char *raw_identifier = LLVMGetModuleIdentifier(self.get(), &len); auto id = std::string(raw_identifier, len); return fmt::format("", id); }) .def("__str__", - [](PyModule &m) { + [](PymModule &m) { char *str = LLVMPrintModuleToString(m.get()); std::string strCopy(str); LLVMDisposeMessage(str); @@ -1394,85 +1394,85 @@ void bindOtherClasses(nb::module_ &m) { }, "Return a string representation of the module") .def("__enter__", - [](PyModule &self) { + [](PymModule &self) { return &self; }) - .def("__exit__", [](PyModule &self, nb::args args, nb::kwargs kwargs) {}) + .def("__exit__", [](PymModule &self, nb::args args, nb::kwargs kwargs) {}) .def_prop_ro("first_global_variable", - [](PyModule &m) -> optional { + [](PymModule &m) -> optional { auto res = LLVMGetFirstGlobal(m.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalVariable); + WRAP_OPTIONAL_RETURN(res, PymGlobalVariable); }) .def_prop_ro("last_global_variable", - [](PyModule &self) -> optional { + [](PymModule &self) -> optional { auto res = LLVMGetLastGlobal(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalVariable); + WRAP_OPTIONAL_RETURN(res, PymGlobalVariable); }) .def_prop_ro("global_variables", - [](PyModule &m) { + [](PymModule &m) { auto res = LLVMGetFirstGlobal(m.get()); - return PyGlobalVariableIterator(PyGlobalVariable(res)); + return PymGlobalVariableIterator(PymGlobalVariable(res)); }) .def_prop_ro("first_global_ifunc", - [](PyModule &self) -> optional { + [](PymModule &self) -> optional { auto res = LLVMGetFirstGlobalIFunc(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalIFunc); + WRAP_OPTIONAL_RETURN(res, PymGlobalIFunc); }) .def_prop_ro("last_global_ifunc", - [](PyModule &self) -> optional { + [](PymModule &self) -> optional { auto res = LLVMGetLastGlobalIFunc(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalIFunc); + WRAP_OPTIONAL_RETURN(res, PymGlobalIFunc); }) .def_prop_ro("global_ifuncs", - [](PyModule &self) { + [](PymModule &self) { auto res = LLVMGetFirstGlobalIFunc(self.get()); - return PyGlobalIFuncIterator(PyGlobalIFunc(res)); + return PymGlobalIFuncIterator(PymGlobalIFunc(res)); }) .def_prop_ro("first_global_alias", - [](PyModule &self) -> optional { + [](PymModule &self) -> optional { auto res = LLVMGetFirstGlobalAlias(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalAlias); + WRAP_OPTIONAL_RETURN(res, PymGlobalAlias); }) .def_prop_ro("last_global_alias", - [](PyModule &self) -> optional { + [](PymModule &self) -> optional { auto res = LLVMGetLastGlobalAlias(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalAlias); + WRAP_OPTIONAL_RETURN(res, PymGlobalAlias); }) .def_prop_ro("global_aliases", - [](PyModule &self) { + [](PymModule &self) { auto res = LLVMGetFirstGlobalAlias(self.get()); - return PyGlobalAliasIterator(PyGlobalAlias(res)); + return PymGlobalAliasIterator(PymGlobalAlias(res)); }) .def_prop_ro("first_named_metadata", - [](PyModule &m) -> optional { + [](PymModule &m) -> optional { auto res = LLVMGetFirstNamedMetadata(m.get()); - WRAP_OPTIONAL_RETURN(res, PyNamedMDNode); + WRAP_OPTIONAL_RETURN(res, PymNamedMDNode); }, "Obtain an iterator to the first NamedMDNode in a Module.") .def_prop_ro("last_named_metadata", - [](PyModule &m) -> optional { + [](PymModule &m) -> optional { auto res = LLVMGetLastNamedMetadata(m.get()); - WRAP_OPTIONAL_RETURN(res, PyNamedMDNode); + WRAP_OPTIONAL_RETURN(res, PymNamedMDNode); }, "Obtain an iterator to the last NamedMDNode in a Module.") .def_prop_ro("named_metadatas", - [](PyModule &m) { + [](PymModule &m) { auto res = LLVMGetFirstNamedMetadata(m.get()); - return PyNamedMDNodeIterator(PyNamedMDNode(res)); + return PymNamedMDNodeIterator(PymNamedMDNode(res)); }, "Obtain an iterator to the first NamedMDNode in a Module.") .def_prop_ro("context", - [](PyModule &m) { - return PyContext(LLVMGetModuleContext(m.get())); + [](PymModule &m) { + return PymContext(LLVMGetModuleContext(m.get())); }, "Obtain the context to which this module is associated.") .def_prop_rw("id", - [](PyModule &m) { + [](PymModule &m) { size_t len; const char *identifier = LLVMGetModuleIdentifier(m.get(), &len); return std::string(identifier, len); }, - [](PyModule &m, const std::string &id) { + [](PymModule &m, const std::string &id) { return LLVMSetModuleIdentifier(m.get(), id.c_str(), id.size()); }, @@ -1481,81 +1481,81 @@ void bindOtherClasses(nb::module_ &m) { nb::for_setter("Set the module identifier.\n" "Origin Function: LLVMGetModuleIdentifier.")) .def_prop_rw("source_file_name", - [](PyModule &m) { + [](PymModule &m) { size_t len; const char* sfn = LLVMGetSourceFileName(m.get(), &len); return std::string(sfn, len); }, - [](PyModule &m, const std::string &name) { + [](PymModule &m, const std::string &name) { return LLVMSetSourceFileName(m.get(), name.c_str(), name.size()); }, "name"_a = "") .def_prop_rw("data_layout", - [](PyModule &m) { + [](PymModule &m) { return LLVMGetDataLayoutStr(m.get()); }, - [](PyModule &m, const std::string &dlstr) { + [](PymModule &m, const std::string &dlstr) { return LLVMSetDataLayout(m.get(), dlstr.c_str()); }, nb::for_getter("Obtain the data layout for a module."), nb::for_setter("Set the data layout for a module.")) .def_prop_rw("target", - [](PyModule &m) { + [](PymModule &m) { return LLVMGetTarget(m.get()); }, - [](PyModule &m, const std::string &triple) { + [](PymModule &m, const std::string &triple) { return LLVMSetTarget(m.get(), triple.c_str()); }, nb::for_getter("Obtain the target triple for a module."), nb::for_setter("Set the target triple for a module.")) .def_prop_rw("inline_asm", - [](PyModule &m) { + [](PymModule &m) { size_t len; const char *iasm = LLVMGetModuleInlineAsm(m.get(), &len); return std::string(iasm, len); }, - [](PyModule &m, std::string &iasm) { + [](PymModule &m, std::string &iasm) { // NOTE LLVMSetModuleInlineAsm is deprecated return LLVMSetModuleInlineAsm2(m.get(), iasm.c_str(), iasm.size()); }) .def_prop_ro("first_function", - [](PyModule &m) { - return PyFunction(LLVMGetFirstFunction(m.get())); + [](PymModule &m) { + return PymFunction(LLVMGetFirstFunction(m.get())); }, "Obtain an iterator to the first Function in a Module.") .def_prop_ro("last_function", - [](PyModule &m) { - return PyFunction(LLVMGetLastFunction(m.get())); + [](PymModule &m) { + return PymFunction(LLVMGetLastFunction(m.get())); }, "Obtain an iterator to the last Function in a Module.") .def_prop_ro("functions", - [](PyModule &m) { - return PyFunctionIterator(PyFunction(LLVMGetFirstFunction(m.get()))); + [](PymModule &m) { + return PymFunctionIterator(PymFunction(LLVMGetFirstFunction(m.get()))); }) .def("create_function_pass_manager", - [](PyModule &self) { - return PyFunctionPassManager(LLVMCreateFunctionPassManagerForModule(self.get())); + [](PymModule &self) { + return PymFunctionPassManager(LLVMCreateFunctionPassManagerForModule(self.get())); }, "Constructs a new function-by-function pass pipeline over the module" "provider. It does not take ownership of the module provider. This type of" "pipeline is suitable for code generation and JIT compilation tasks.") .def("create_module_provider", - [](PyModule &self) { - return PyModuleProvider(LLVMCreateModuleProviderForExistingModule + [](PymModule &self) { + return PymModuleProvider(LLVMCreateModuleProviderForExistingModule (self.get())); }) .def("get_intrinsic_declaration", - [](PyModule &module, unsigned ID, std::vector paramTypes) { + [](PymModule &module, unsigned ID, std::vector paramTypes) { size_t paramCnt = paramTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, paramTypes, params, paramCnt); - return PyFunction(LLVMGetIntrinsicDeclaration(module.get(), ID, params.data(), + return PymFunction(LLVMGetIntrinsicDeclaration(module.get(), ID, params.data(), paramCnt)); }, "id"_a, "param_types"_a, "Create or insert the declaration of an intrinsic. For overloaded intrinsics," "parameter types must be provided to uniquely identify an overload.") .def("verify", - [](PyModule &self, LLVMVerifierFailureAction action) -> optional { + [](PymModule &self, LLVMVerifierFailureAction action) -> optional { char *outMessage; auto res = LLVMVerifyModule(self.get(), action, &outMessage) == 0; if (!res) { @@ -1577,71 +1577,71 @@ void bindOtherClasses(nb::module_ &m) { "\tIf success, return None. Otherwise, optionally(based on action) return " "a human-readable description if any invalid constructs.") .def("add_alias", - [](PyModule &self, PyType &valueType, unsigned addrSpace, PyValue aliasee, + [](PymModule &self, PymType &valueType, unsigned addrSpace, PymValue aliasee, const char *name) { - return PyGlobalAlias(LLVMAddAlias2 + return PymGlobalAlias(LLVMAddAlias2 (self.get(), valueType.get(), addrSpace, aliasee.get(), name)); }, "value_type"_a, "addr_space"_a, "aliasee"_a, "name"_a = "", "Add a GlobalAlias with the given value type, address space and aliasee.") .def("get_named_global_alias", - [](PyModule &self, std::string &name) { - return PyGlobalAlias(LLVMGetNamedGlobalAlias + [](PymModule &self, std::string &name) { + return PymGlobalAlias(LLVMGetNamedGlobalAlias (self.get(), name.c_str(), name.size())); }, "name"_a = "", "Obtain a GlobalAlias value from by its name.") .def("add_global", - [](PyModule &self, PyType &type, const char *name) { - return PyGlobalVariable(LLVMAddGlobal(self.get(), type.get(), name)); + [](PymModule &self, PymType &type, const char *name) { + return PymGlobalVariable(LLVMAddGlobal(self.get(), type.get(), name)); }, "type"_a, "name"_a = "") .def("add_global_in_address_space", - [](PyModule &self, PyType &type, const char *name, unsigned addressSpace) { - return PyGlobalVariable(LLVMAddGlobalInAddressSpace + [](PymModule &self, PymType &type, const char *name, unsigned addressSpace) { + return PymGlobalVariable(LLVMAddGlobalInAddressSpace (self.get(), type.get(), name, addressSpace)); }, "type"_a, "name"_a = "", "address_space"_a = 0) .def("get_named_global", - [](PyModule &self, const char *name) { - return PyGlobalVariable(LLVMGetNamedGlobal(self.get(), name)); + [](PymModule &self, const char *name) { + return PymGlobalVariable(LLVMGetNamedGlobal(self.get(), name)); }) .def("add_global_indirect_func", - [](PyModule &self, PyType &type, unsigned addrSpace, PyConstant resolver, + [](PymModule &self, PymType &type, unsigned addrSpace, PymConstant resolver, std::string &name) { - return PyGlobalIFunc(LLVMAddGlobalIFunc + return PymGlobalIFunc(LLVMAddGlobalIFunc (self.get(), name.c_str(), name.size(), type.get(), addrSpace, resolver.get())); }, "type"_a, "addr_space"_a, "resolver"_a, "name"_a = "") .def("get_named_global_ifunc", - [](PyModule &self, std::string &name) -> std::optional { + [](PymModule &self, std::string &name) -> std::optional { auto res = LLVMGetNamedGlobalIFunc(self.get(), name.c_str(), name.size()); - WRAP_OPTIONAL_RETURN(res, PyGlobalIFunc); + WRAP_OPTIONAL_RETURN(res, PymGlobalIFunc); }) .def("add_function", - [](PyModule &m, PyTypeFunction &functionTy, std::string &name) { - return PyFunction(LLVMAddFunction(m.get(), name.c_str(), functionTy.get())); + [](PymModule &m, PymTypeFunction &functionTy, std::string &name) { + return PymFunction(LLVMAddFunction(m.get(), name.c_str(), functionTy.get())); }, "function_type"_a, "name"_a = "", "Add a function to a module under a specified name.") .def("get_named_function", - [](PyModule &m, std::string &name) { - return PyFunction(LLVMGetNamedFunction(m.get(), name.c_str())); + [](PymModule &m, std::string &name) { + return PymFunction(LLVMGetNamedFunction(m.get(), name.c_str())); }, "name"_a = "", "Obtain a Function value from a Module by its name.") .def("get_named_metadata", - [](PyModule &m, std::string &name) -> optional { + [](PymModule &m, std::string &name) -> optional { auto res = LLVMGetNamedMetadata(m.get(), name.c_str(), name.size()); - WRAP_OPTIONAL_RETURN(res, PyNamedMDNode); + WRAP_OPTIONAL_RETURN(res, PymNamedMDNode); }, "name"_a = "", "Retrieve a NamedMDNode with the given name, returning NULL if no such" "node exists.") .def("get_or_insert_named_metadata", - [](PyModule &m, std::string &name) { - return PyNamedMDNode + [](PymModule &m, std::string &name) { + return PymNamedMDNode (LLVMGetOrInsertNamedMetadata (m.get(), name.c_str(), name.size())); }, @@ -1649,16 +1649,16 @@ void bindOtherClasses(nb::module_ &m) { "Retrieve a NamedMDNode with the given name, creating a new node if no such" "node exists.") .def("get_named_metadata_operands_num", - [](PyModule &m, std::string &name) { + [](PymModule &m, std::string &name) { return LLVMGetNamedMetadataNumOperands(m.get(), name.c_str()); }, "name"_a = "", "Obtain the number of operands for named metadata in a module.") .def("get_named_metadata_operands", - [](PyModule &m, std::string &name) { + [](PymModule &m, std::string &name) { int num = LLVMGetNamedMetadataNumOperands(m.get(), name.c_str()); std::vector dest(num); LLVMGetNamedMetadataOperands(m.get(), name.c_str(), dest.data()); - WRAP_VECTOR_FROM_DEST_AUTO(PyValue, num, res, dest); + WRAP_VECTOR_FROM_DEST_AUTO(PymValue, num, res, dest); return res; }, "name"_a = "", @@ -1668,34 +1668,34 @@ void bindOtherClasses(nb::module_ &m) { "array will be populated with the LLVMValueRef instances. Each" "instance corresponds to a llvm::MDNode.") .def("add_named_metadata_operand", - [](PyModule &m, std::string &name, PyValue &val) { + [](PymModule &m, std::string &name, PymValue &val) { return LLVMAddNamedMetadataOperand(m.get(), name.c_str(), val.get()); }, "Add an operand to named metadata.") .def("clone", - [](PyModule &m) { - return PyModule(LLVMCloneModule(m.get())); + [](PymModule &m) { + return PymModule(LLVMCloneModule(m.get())); }, "Return an exact copy of the specified module.") .def("copy_module_flags_metadata", - [](PyModule &m) { + [](PymModule &m) { size_t Len; LLVMModuleFlagEntry *flags = LLVMCopyModuleFlagsMetadata(m.get(), &Len); - auto res = PyModuleFlagEntries(flags, Len); + auto res = PymModuleFlagEntries(flags, Len); return res; }, "Returns the module flags as an array of flag-key-value triples.") .def("get_flag", - [](PyModule &m, const std::string &key) -> optional { + [](PymModule &m, const std::string &key) -> optional { auto res = LLVMGetModuleFlag(m.get(), key.c_str(), key.size()); - WRAP_OPTIONAL_RETURN(res, PyMetadata); + WRAP_OPTIONAL_RETURN(res, PymMetadata); }, "key"_a, "Return the corresponding value if Key appears in module flags, otherwise" "return null.") .def("add_flag", - [](PyModule &m, LLVMModuleFlagBehavior behavior, - const std::string key, PyMetadata &val) { + [](PymModule &m, LLVMModuleFlagBehavior behavior, + const std::string key, PymMetadata &val) { return LLVMAddModuleFlag(m.get(), behavior, key.c_str(), key.size(), val.get()); }, @@ -1703,12 +1703,12 @@ void bindOtherClasses(nb::module_ &m) { "Add a module-level flag to the module-level flags metadata if it doesn't" "already exist.") .def("dump", - [](PyModule &m) { + [](PymModule &m) { return LLVMDumpModule(m.get()); }, "Dump a representation of a module to stderr.") .def("print_to_file", - [](PyModule &m, const std::string &filename) { + [](PymModule &m, const std::string &filename) { char *errorMessage = nullptr; LLVMBool res = LLVMPrintModuleToFile(m.get(), filename.c_str(), &errorMessage); @@ -1724,22 +1724,22 @@ void bindOtherClasses(nb::module_ &m) { "Print a representation of a module to a file.\n" ":raises RuntimeError") .def("append_inline_asm", - [](PyModule &m, std::string &iasm) { + [](PymModule &m, std::string &iasm) { return LLVMAppendModuleInlineAsm(m.get(), iasm.c_str(), iasm.size()); }) .def("get_type_by_name", - [](PyModule &m, std::string &name) { - return PyTypeAuto(LLVMGetTypeByName(m.get(), name.c_str())); + [](PymModule &m, std::string &name) { + return PymTypeAuto(LLVMGetTypeByName(m.get(), name.c_str())); }, "name"_a = "", "Deprecated: Use LLVMGetTypeByName2 instead."); ModuleFlagEntriesClass .def("__repr__", - [](PyModuleFlagEntries &self) { + [](PymModuleFlagEntries &self) { return ""; }) .def("get_behavior", - [](PyModuleFlagEntries &self, unsigned index) { + [](PymModuleFlagEntries &self, unsigned index) { // TODO test whether LLVMModuleFlagEntriesGetFlagBehavior will // check index is in bound return LLVMModuleFlagEntriesGetFlagBehavior(self.get(), index); @@ -1747,7 +1747,7 @@ void bindOtherClasses(nb::module_ &m) { "index"_a, "Returns the flag behavior for a module flag entry at a specific index.") .def("get_key", - [](PyModuleFlagEntries &self, unsigned index) { + [](PymModuleFlagEntries &self, unsigned index) { size_t len; const char *str = LLVMModuleFlagEntriesGetKey(self.get(), index, &len); return std::string(str, len); @@ -1755,9 +1755,9 @@ void bindOtherClasses(nb::module_ &m) { "index"_a, "Returns the key for a module flag entry at a specific index.") .def("get_metadata", - [](PyModuleFlagEntries &self, unsigned index) { + [](PymModuleFlagEntries &self, unsigned index) { // TODO can this return null? - return PyMetadata(LLVMModuleFlagEntriesGetMetadata(self.get(), index)); + return PymMetadata(LLVMModuleFlagEntriesGetMetadata(self.get(), index)); }, "index"_a, "Returns the metadata for a module flag entry at a specific index."); diff --git a/src/llvm/Core/miscClasses.h b/src/llvm/Core/miscClasses.h index ac780c8..ca98116 100644 --- a/src/llvm/Core/miscClasses.h +++ b/src/llvm/Core/miscClasses.h @@ -7,8 +7,8 @@ #define BUILDER_BIND_BINARY_OP(NAME, FUNCTION) \ .def(#NAME, \ - [](PyBuilder &self, PyValue &lhs, PyValue &rhs, const char *name) { \ - return PyValueAuto(FUNCTION(self.get(), lhs.get(), rhs.get(), name)); \ + [](PymBuilder &self, PymValue &lhs, PymValue &rhs, const char *name) { \ + return PymValueAuto(FUNCTION(self.get(), lhs.get(), rhs.get(), name)); \ }, \ "lhs"_a, "rhs"_a, "name"_a = "") @@ -44,8 +44,8 @@ #define BUILDER_BIND_CAST_OP(NAME, FUNCTION) \ .def(#NAME, \ - [](PyBuilder &self, PyValue &val, PyType &destType, const char *name) { \ - return PyValueAuto(FUNCTION(self.get(), val.get(), destType.get(), name)); \ + [](PymBuilder &self, PymValue &val, PymType &destType, const char *name) { \ + return PymValueAuto(FUNCTION(self.get(), val.get(), destType.get(), name)); \ }, \ "val"_a, "dest_type"_a, "name"_a = "") diff --git a/src/llvm/Core/type.cpp b/src/llvm/Core/type.cpp index 7b40dfc..d220fa8 100644 --- a/src/llvm/Core/type.cpp +++ b/src/llvm/Core/type.cpp @@ -17,83 +17,83 @@ template using optional = std::optional; void bindTypeClasses(nb::module_ &m) { - auto TypeClass = nb::class_>(m, "Type", "Type"); - auto TypeIntClass = nb::class_(m, "IntType", "IntType"); - auto TypeRealClass = nb::class_(m, "RealType", "RealType"); - auto TypeFunctionClass = nb::class_ (m, "FunctionType", "FunctionType"); - auto TypeStructClass = nb::class_ (m, "StructType", "StructType"); - auto TypeSequenceClass = nb::class_(m, "SequenceType", "SequenceType"); - auto TypeArrayClass = nb::class_(m, "ArrayType", "ArrayType"); - auto TypePointerClass = nb::class_(m, "PointerType", "PointerType"); - auto TypeVectorClass = nb::class_(m, "VectorType", "VectorType"); - auto TypeVoidClass = nb::class_(m, "VoidType", "VoidType"); - auto TypeLabelClass = nb::class_(m, "LabelType", "LabelType"); - auto TypeX86MMXClass = nb::class_(m, "X86MMXType", "X86MMXType"); - auto TypeX86AMXClass = nb::class_(m, "X86AMXType", "X86AMXType"); - auto TypeTokenClass = nb::class_(m, "TokenType", "TokenType"); - auto TypeMetadataClass = nb::class_(m, "MetadataType", "MetadataType"); - auto TypeTargetExtClass = nb::class_(m, "TargetExtType", "TargetExtType"); + auto TypeClass = nb::class_>(m, "Type", "Type"); + auto TypeIntClass = nb::class_(m, "IntType", "IntType"); + auto TypeRealClass = nb::class_(m, "RealType", "RealType"); + auto TypeFunctionClass = nb::class_ (m, "FunctionType", "FunctionType"); + auto TypeStructClass = nb::class_ (m, "StructType", "StructType"); + auto TypeSequenceClass = nb::class_(m, "SequenceType", "SequenceType"); + auto TypeArrayClass = nb::class_(m, "ArrayType", "ArrayType"); + auto TypePointerClass = nb::class_(m, "PointerType", "PointerType"); + auto TypeVectorClass = nb::class_(m, "VectorType", "VectorType"); + auto TypeVoidClass = nb::class_(m, "VoidType", "VoidType"); + auto TypeLabelClass = nb::class_(m, "LabelType", "LabelType"); + auto TypeX86MMXClass = nb::class_(m, "X86MMXType", "X86MMXType"); + auto TypeX86AMXClass = nb::class_(m, "X86AMXType", "X86AMXType"); + auto TypeTokenClass = nb::class_(m, "TokenType", "TokenType"); + auto TypeMetadataClass = nb::class_(m, "MetadataType", "MetadataType"); + auto TypeTargetExtClass = nb::class_(m, "TargetExtType", "TargetExtType"); TypeClass .def("__repr__", - [](PyType &self) { + [](PymType &self) { auto kind = get_repr_str(LLVMGetTypeKind(self.get())); return fmt::format("", kind, get_type_str(self)); }) .def("__str__", &get_type_str) .def_prop_ro("align", - [](PyType &t) { - return PyConstantExpr(LLVMAlignOf(t.get())); + [](PymType &t) { + return PymConstantExpr(LLVMAlignOf(t.get())); }) .def_prop_ro("size", - [](PyType &t) { - return PyConstantExpr(LLVMSizeOf(t.get())); + [](PymType &t) { + return PymConstantExpr(LLVMSizeOf(t.get())); }) .def_prop_ro("kind", - [](PyType &t) { return LLVMGetTypeKind(t.get()); }, + [](PymType &t) { return LLVMGetTypeKind(t.get()); }, "Obtain the enumerated type of a Type instance.") .def_prop_ro("is_sized", - [](PyType &t) { return LLVMTypeIsSized(t.get()) != 0; }, + [](PymType &t) { return LLVMTypeIsSized(t.get()) != 0; }, "Whether the type has a known size.\n\n" "Things that don't have a size are abstract types, labels, and void.a") .def_prop_ro("context", - [](PyType &t) { return PyContext(LLVMGetTypeContext(t.get())); }, + [](PymType &t) { return PymContext(LLVMGetTypeContext(t.get())); }, "Obtain the context to which this type instance is associated.") .def_prop_ro("sub_type_number", - [](PyType &t) { + [](PymType &t) { return LLVMGetNumContainedTypes(t.get()); }) .def_prop_ro("sub_types", - [](PyType &t) { + [](PymType &t) { unsigned num = LLVMGetNumContainedTypes(t.get()); std::vector arr(num); LLVMGetSubtypes(t.get(), arr.data()); - WRAP_VECTOR_FROM_DEST(PyTypeSequence, num, res, arr); + WRAP_VECTOR_FROM_DEST(PymTypeSequence, num, res, arr); return res; }) .def("null", - [](PyType &t) { - return PyValueAuto(LLVMConstNull(t.get())); + [](PymType &t) { + return PymValueAuto(LLVMConstNull(t.get())); }, "Obtain a constant value referring to the null instance of the type.") .def("pointer_null", - [](PyType &t) { - return PyValueAuto(LLVMConstPointerNull(t.get())); + [](PymType &t) { + return PymValueAuto(LLVMConstPointerNull(t.get())); }, "Obtain a constant that is a constant pointer pointing to NULL for the" "type.") .def("undef", - [](PyType &t) { - return PyUndefValue(LLVMGetUndef(t.get())); + [](PymType &t) { + return PymUndefValue(LLVMGetUndef(t.get())); }, "Obtain a constant value referring to an undefined value of a type.") .def("poison", - [](PyType &t) { - return PyPoisonValue(LLVMGetPoison(t.get())); + [](PymType &t) { + return PymPoisonValue(LLVMGetPoison(t.get())); }, "Obtain a constant value referring to a poison value of a type.") .def("dump", - [](PyType &self) { + [](PymType &self) { return LLVMDumpType(self.get()); }, "Dump a representation of a type to stderr."); @@ -101,57 +101,57 @@ void bindTypeClasses(nb::module_ &m) { TypeIntClass .def("__repr__", - [](PyTypeInt &self) { + [](PymTypeInt &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeInt *t, PyContext &c, unsigned numBits) { - new (t) PyTypeInt(LLVMIntTypeInContext(c.get(), numBits)); + [](PymTypeInt *t, PymContext &c, unsigned numBits) { + new (t) PymTypeInt(LLVMIntTypeInContext(c.get(), numBits)); }, "context"_a, "num_bits"_a) .def_static("Int1", - [](PyContext &c) { return PyTypeInt(LLVMInt1TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt1TypeInContext(c.get())); }, "context"_a) .def_static("Int8", - [](PyContext &c) { return PyTypeInt(LLVMInt8TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt8TypeInContext(c.get())); }, "context"_a) .def_static("Int16", - [](PyContext &c) { return PyTypeInt(LLVMInt16TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt16TypeInContext(c.get())); }, "context"_a) .def_static("Int32", - [](PyContext &c) { return PyTypeInt(LLVMInt32TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt32TypeInContext(c.get())); }, "context"_a) .def_static("Int64", - [](PyContext &c) { return PyTypeInt(LLVMInt64TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt64TypeInContext(c.get())); }, "context"_a) .def_static("Int128", - [](PyContext &c) { return PyTypeInt(LLVMInt128TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeInt(LLVMInt128TypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("GlobalInt1", - [](nb::handle) { return PyTypeInt(LLVMInt1Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt1Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalInt8", - [](nb::handle) { return PyTypeInt(LLVMInt8Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt8Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalInt16", - [](nb::handle) { return PyTypeInt(LLVMInt16Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt16Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalInt32", - [](nb::handle) { return PyTypeInt(LLVMInt32Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt32Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalInt64", - [](nb::handle) { return PyTypeInt(LLVMInt64Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt64Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalInt128", - [](nb::handle) { return PyTypeInt(LLVMInt128Type()); }, + [](nb::handle) { return PymTypeInt(LLVMInt128Type()); }, "Get type from global context.") .def_static("Global", - [](unsigned numBits) { return PyTypeInt(LLVMIntType(numBits)); }, + [](unsigned numBits) { return PymTypeInt(LLVMIntType(numBits)); }, "Get type from global context.") .def_prop_ro("width", - [](PyTypeInt &t) { return LLVMGetIntTypeWidth(t.get()); }) + [](PymTypeInt &t) { return LLVMGetIntTypeWidth(t.get()); }) .def("all_ones", - [](PyTypeInt &t) { - return PyValueAuto(LLVMConstAllOnes(t.get())); + [](PymTypeInt &t) { + return PymValueAuto(LLVMConstAllOnes(t.get())); }, "Obtain a constant value referring to the instance of the type" "consisting of all ones."); @@ -159,137 +159,137 @@ void bindTypeClasses(nb::module_ &m) { TypeRealClass .def("__repr__", - [](PyTypeReal &self) { + [](PymTypeReal &self) { return fmt::format("", get_type_str(self)); }) .def_static("Half", - [](PyContext &c) { return PyTypeReal(LLVMHalfTypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMHalfTypeInContext(c.get())); }, "context"_a) .def_static("Bfloat", - [](PyContext &c) { return PyTypeReal(LLVMBFloatTypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMBFloatTypeInContext(c.get())); }, "context"_a) .def_static("Float", - [](PyContext &c) { return PyTypeReal(LLVMFloatTypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMFloatTypeInContext(c.get())); }, "context"_a) .def_static("Double", - [](PyContext &c) { return PyTypeReal(LLVMDoubleTypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMDoubleTypeInContext(c.get())); }, "context"_a) .def_static("X86FP80", - [](PyContext &c) { return PyTypeReal(LLVMX86FP80TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMX86FP80TypeInContext(c.get())); }, "context"_a) .def_static("FP128", - [](PyContext &c) { return PyTypeReal(LLVMFP128TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMFP128TypeInContext(c.get())); }, "context"_a) .def_static("PPCFP128", - [](PyContext &c) { return PyTypeReal(LLVMPPCFP128TypeInContext(c.get())); }, + [](PymContext &c) { return PymTypeReal(LLVMPPCFP128TypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("GlobalHalf", - [](nb::handle){ return PyTypeReal(LLVMHalfType()); }, + [](nb::handle){ return PymTypeReal(LLVMHalfType()); }, "Get type from global context.") .def_prop_ro_static("GlobalBfloat", - [](nb::handle){ return PyTypeReal(LLVMBFloatType()); }, + [](nb::handle){ return PymTypeReal(LLVMBFloatType()); }, "Get type from global context.") .def_prop_ro_static("GlobalFloat", - [](nb::handle){ return PyTypeReal(LLVMFloatType()); }, + [](nb::handle){ return PymTypeReal(LLVMFloatType()); }, "Get type from global context.") .def_prop_ro_static("GlobalDouble", - [](nb::handle){ return PyTypeReal(LLVMDoubleType()); }, + [](nb::handle){ return PymTypeReal(LLVMDoubleType()); }, "Get type from global context.") .def_prop_ro_static("GlobalX86FP80", - [](nb::handle){ return PyTypeReal(LLVMX86FP80Type()); }, + [](nb::handle){ return PymTypeReal(LLVMX86FP80Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalFP128", - [](nb::handle){ return PyTypeReal(LLVMFP128Type()); }, + [](nb::handle){ return PymTypeReal(LLVMFP128Type()); }, "Get type from global context.") .def_prop_ro_static("GlobalPPCFP128", - [](nb::handle){ return PyTypeReal(LLVMPPCFP128Type()); }, + [](nb::handle){ return PymTypeReal(LLVMPPCFP128Type()); }, "Get type from global context."); TypeFunctionClass .def("__repr__", - [](PyTypeFunction &self) { + [](PymTypeFunction &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeFunction *t, PyType &returnType, std::vector ¶mTypes, bool isVarArg) { + [](PymTypeFunction *t, PymType &returnType, std::vector ¶mTypes, bool isVarArg) { unsigned param_count = paramTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, paramTypes, rawParamTypes, param_count) - new (t) PyTypeFunction(LLVMFunctionType(returnType.get(), rawParamTypes.data(), + new (t) PymTypeFunction(LLVMFunctionType(returnType.get(), rawParamTypes.data(), param_count, isVarArg)); }, "return_type"_a, "param_types"_a, "is_var_arg"_a, "Obtain a function type consisting of a specified signature.") .def_prop_ro("is_vararg", - [](PyTypeFunction &t) { return LLVMIsFunctionVarArg(t.get()) != 0; }, + [](PymTypeFunction &t) { return LLVMIsFunctionVarArg(t.get()) != 0; }, "Returns whether a function type is variadic.") .def_prop_ro("return_type", - [](PyTypeFunction &t) { return PyTypeAuto(LLVMGetReturnType(t.get())); }, + [](PymTypeFunction &t) { return PymTypeAuto(LLVMGetReturnType(t.get())); }, "Obtain the Type this function Type returns.") .def_prop_ro("params_num", - [](PyTypeFunction &t) { return LLVMCountParamTypes(t.get()); }, + [](PymTypeFunction &t) { return LLVMCountParamTypes(t.get()); }, "Obtain the number of parameters this function accepts.") .def_prop_ro("param_types", - [](PyTypeFunction &t) { + [](PymTypeFunction &t) { unsigned param_number = LLVMCountParamTypes(t.get()); std::vector dest(param_number); LLVMGetParamTypes(t.get(), dest.data()); - WRAP_VECTOR_FROM_DEST(PyTypeFunction, param_number, res, dest); + WRAP_VECTOR_FROM_DEST(PymTypeFunction, param_number, res, dest); return res; }, "Obtain the types of a function's parameters."); TypeStructClass .def("__repr__", - [](PyTypeStruct &self) { + [](PymTypeStruct &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeStruct *t, PyContext &c, std::vector &elementTypes, bool packed) { + [](PymTypeStruct *t, PymContext &c, std::vector &elementTypes, bool packed) { unsigned elem_count = elementTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, elementTypes, rawElemTypes, elem_count); - new (t) PyTypeStruct(LLVMStructTypeInContext(c.get(), rawElemTypes.data(), + new (t) PymTypeStruct(LLVMStructTypeInContext(c.get(), rawElemTypes.data(), elem_count, packed)); }, "context"_a, "element_types"_a, "packed"_a, "Create a new structure type in context.") .def("__init__", - [](PyTypeStruct *t, PyContext &c, std::string name) { - new (t) PyTypeStruct(LLVMStructCreateNamed(c.get(), name.c_str())); + [](PymTypeStruct *t, PymContext &c, std::string name) { + new (t) PymTypeStruct(LLVMStructCreateNamed(c.get(), name.c_str())); }, "context"_a, "name"_a = "", "Create an empty structure in the context having a specified name.") .def_static("Global", - [](std::vector elementTypes, bool packed) { + [](std::vector elementTypes, bool packed) { unsigned elem_count = elementTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, elementTypes, rawElemTypes, elem_count); - return PyTypeStruct(LLVMStructType(rawElemTypes.data(), elem_count, packed)); + return PymTypeStruct(LLVMStructType(rawElemTypes.data(), elem_count, packed)); }, "element_types"_a, "packed"_a, "Create a new structure type in the global context.") - .def_prop_ro("name", [](PyTypeStruct &t) { return LLVMGetStructName(t.get()); }) + .def_prop_ro("name", [](PymTypeStruct &t) { return LLVMGetStructName(t.get()); }) .def_prop_ro("elem_number", - [](PyTypeStruct &t) { + [](PymTypeStruct &t) { return LLVMCountStructElementTypes(t.get()); }) .def_prop_ro("elem_types", - [](PyTypeStruct &t) { + [](PymTypeStruct &t) { unsigned num = LLVMCountStructElementTypes(t.get()); std::vector dest(num); LLVMGetStructElementTypes(t.get(), dest.data()); - WRAP_VECTOR_FROM_DEST(PyTypeStruct, num, res, dest); + WRAP_VECTOR_FROM_DEST(PymTypeStruct, num, res, dest); return res; }) .def_prop_ro("is_packed", - [](PyTypeStruct &t) { return LLVMIsPackedStruct(t.get()) != 0; }, + [](PymTypeStruct &t) { return LLVMIsPackedStruct(t.get()) != 0; }, "Determine whether a structure is packed.") .def_prop_ro("is_opaque", - [](PyTypeStruct &t) { return LLVMIsOpaqueStruct(t.get()) != 0; }) + [](PymTypeStruct &t) { return LLVMIsOpaqueStruct(t.get()) != 0; }) .def_prop_ro("is_literal", - [](PyTypeStruct &t) { return LLVMIsLiteralStruct(t.get()) != 0; }, + [](PymTypeStruct &t) { return LLVMIsLiteralStruct(t.get()) != 0; }, "Determine whether a structure is literal.") .def("set_body", - [](PyTypeStruct &t, std::vector elementTypes, bool packed) { + [](PymTypeStruct &t, std::vector elementTypes, bool packed) { unsigned elem_count = elementTypes.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, elementTypes, rawElemTypes, elem_count); return LLVMStructSetBody(t.get(), rawElemTypes.data(), elem_count, packed); @@ -297,33 +297,33 @@ void bindTypeClasses(nb::module_ &m) { "elem_types"_a, "packed"_a, "Set the contents of a structure type.") .def("get_type_at_index", - [](PyTypeStruct &t, unsigned i) -> optional { + [](PymTypeStruct &t, unsigned i) -> optional { auto res = LLVMStructGetTypeAtIndex(t.get(), i); - WRAP_OPTIONAL_RETURN(res, PyTypeAuto); + WRAP_OPTIONAL_RETURN(res, PymTypeAuto); }, "index"_a, "Get the type of the element at a given index in the structure."); TypeSequenceClass .def("__repr__", - [](PyTypeSequence &self) { + [](PymTypeSequence &self) { return fmt::format("", get_type_str(self)); }) .def_prop_ro("element_type", // TODO test pointer type - [](PyTypeSequence &t) { - return PyTypeAuto(LLVMGetElementType(t.get())); + [](PymTypeSequence &t) { + return PymTypeAuto(LLVMGetElementType(t.get())); }); TypeArrayClass .def("__repr__", - [](PyTypeArray &self) { + [](PymTypeArray &self) { return fmt::format("", get_type_str(self)); }) // NOTE We use LLVMArrayType2 instead of LLVMArrayType to coordinate // with the `length` property .def("__init__", - [](PyTypeArray *t, PyType &elementType, uint64_t elementCount) { - new (t) PyTypeArray(LLVMArrayType2(elementType.get(), elementCount)); + [](PymTypeArray *t, PymType &elementType, uint64_t elementCount) { + new (t) PymTypeArray(LLVMArrayType2(elementType.get(), elementCount)); }, "elem_type"_a, "elem_count"_a, "Create a fixed size array type that refers to a specific type.\n\n" @@ -332,145 +332,145 @@ void bindTypeClasses(nb::module_ &m) { // LLVMGetArrayLength is deprecated in favor of the API accurate // LLVMGetArrayLength2 .def_prop_ro("length", - [](PyTypeArray &t) { + [](PymTypeArray &t) { return LLVMGetArrayLength2(t.get()); }); TypePointerClass .def("__repr__", - [](PyTypePointer &self) { + [](PymTypePointer &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypePointer *t, PyContext &c, unsigned AddressSpace) { - new (t) PyTypePointer(LLVMPointerTypeInContext(c.get(), AddressSpace)); + [](PymTypePointer *t, PymContext &c, unsigned AddressSpace) { + new (t) PymTypePointer(LLVMPointerTypeInContext(c.get(), AddressSpace)); }, "context"_a, "address_space"_a, "Create an opaque pointer type in a context.") .def("__init__", - [](PyTypePointer *t, PyType &ElementType, unsigned AddressSpace) { - new (t) PyTypePointer(LLVMPointerType(ElementType.get(), AddressSpace)); + [](PymTypePointer *t, PymType &ElementType, unsigned AddressSpace) { + new (t) PymTypePointer(LLVMPointerType(ElementType.get(), AddressSpace)); }, "elem_type"_a, "address_space"_a, "Create a pointer type that points to a defined type.\n\n" "The created type will exist in the context that its pointee type" "exists in.") .def_prop_ro("is_opaque", - [](PyTypePointer &t) { return LLVMPointerTypeIsOpaque(t.get()); }) + [](PymTypePointer &t) { return LLVMPointerTypeIsOpaque(t.get()); }) .def_prop_ro("address_space", - [](PyTypePointer &t) { return LLVMGetPointerAddressSpace(t.get()); }); + [](PymTypePointer &t) { return LLVMGetPointerAddressSpace(t.get()); }); TypeVectorClass .def("__repr__", - [](PyTypeVector &self) { + [](PymTypeVector &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeVector *t, PyType &ElementType, unsigned ElementCount, bool IsScalable) { + [](PymTypeVector *t, PymType &ElementType, unsigned ElementCount, bool IsScalable) { if (IsScalable) { - new (t) PyTypeVector(LLVMScalableVectorType(ElementType.get(), ElementCount)); + new (t) PymTypeVector(LLVMScalableVectorType(ElementType.get(), ElementCount)); } else { - new (t) PyTypeVector(LLVMVectorType(ElementType.get(), ElementCount)); + new (t) PymTypeVector(LLVMVectorType(ElementType.get(), ElementCount)); } }, "elem_type"_a, "elem_count"_a, "is_scalable"_a, "The created type will exist in the context thats its element type" "exists in.") .def_prop_ro_static("__len__", - [](PyTypeVector &t) { return LLVMGetVectorSize(t.get()); }); + [](PymTypeVector &t) { return LLVMGetVectorSize(t.get()); }); TypeVoidClass .def("__repr__", - [](PyTypeVoid &self) { + [](PymTypeVoid &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeVoid *t, PyContext &c) { - new (t) PyTypeVoid(LLVMVoidTypeInContext(c.get())); + [](PymTypeVoid *t, PymContext &c) { + new (t) PymTypeVoid(LLVMVoidTypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("Global", - [](nb::handle) { return PyTypeVoid(LLVMVoidType()); } ); + [](nb::handle) { return PymTypeVoid(LLVMVoidType()); } ); TypeLabelClass .def("__repr__", - [](PyTypeLabel &self) { + [](PymTypeLabel &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeLabel *t, PyContext &c) { - new (t) PyTypeLabel(LLVMLabelTypeInContext(c.get())); + [](PymTypeLabel *t, PymContext &c) { + new (t) PymTypeLabel(LLVMLabelTypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("Global", - [](nb::handle) { return PyTypeLabel(LLVMLabelType()); } ); + [](nb::handle) { return PymTypeLabel(LLVMLabelType()); } ); TypeX86MMXClass .def("__repr__", - [](PyTypeX86MMX &self) { + [](PymTypeX86MMX &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeX86MMX *t, PyContext &c) { - new (t) PyTypeX86MMX(LLVMX86MMXTypeInContext(c.get())); + [](PymTypeX86MMX *t, PymContext &c) { + new (t) PymTypeX86MMX(LLVMX86MMXTypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("Global", - [](nb::handle) { return PyTypeX86MMX(LLVMX86MMXType()); } ); + [](nb::handle) { return PymTypeX86MMX(LLVMX86MMXType()); } ); TypeX86AMXClass .def("__repr__", - [](PyTypeX86AMX &self) { + [](PymTypeX86AMX &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeX86AMX *t, PyContext &c) { - new (t) PyTypeX86AMX(LLVMX86AMXTypeInContext(c.get())); + [](PymTypeX86AMX *t, PymContext &c) { + new (t) PymTypeX86AMX(LLVMX86AMXTypeInContext(c.get())); }, "context"_a) .def_prop_ro_static("Global", - [](nb::handle) { return PyTypeX86AMX(LLVMX86AMXType()); } ); + [](nb::handle) { return PymTypeX86AMX(LLVMX86AMXType()); } ); TypeTokenClass .def("__repr__", - [](PyTypeToken &self) { + [](PymTypeToken &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeToken *t, PyContext &c) { - new (t) PyTypeToken(LLVMTokenTypeInContext(c.get())); + [](PymTypeToken *t, PymContext &c) { + new (t) PymTypeToken(LLVMTokenTypeInContext(c.get())); }, "context"_a); TypeMetadataClass .def("__repr__", - [](PyTypeMetadata &self) { + [](PymTypeMetadata &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeMetadata *t, PyContext &c) { - new (t) PyTypeMetadata(LLVMMetadataTypeInContext(c.get())); + [](PymTypeMetadata *t, PymContext &c) { + new (t) PymTypeMetadata(LLVMMetadataTypeInContext(c.get())); }, "context"_a); TypeTargetExtClass .def("__repr__", - [](PyTypeTargetExt &self) { + [](PymTypeTargetExt &self) { return fmt::format("", get_type_str(self)); }) .def("__init__", - [](PyTypeVoid *t, PyContext &c, std::string &name, std::vector typeParams, + [](PymTypeVoid *t, PymContext &c, std::string &name, std::vector typeParams, std::vector intParams) { unsigned typeParamSize = typeParams.size(); unsigned intParamSize = intParams.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMTypeRef, typeParams, rawTypeParams, typeParamSize); - new (t) PyTypeVoid(LLVMTargetExtTypeInContext + new (t) PymTypeVoid(LLVMTargetExtTypeInContext (c.get(), name.c_str(), rawTypeParams.data(), typeParamSize, intParams.data(), intParamSize)); }); diff --git a/src/llvm/Core/utils.cpp b/src/llvm/Core/utils.cpp index 03ad4bf..9d0437d 100644 --- a/src/llvm/Core/utils.cpp +++ b/src/llvm/Core/utils.cpp @@ -3,13 +3,13 @@ #include #include -PyMetadataAsValue* getMoreSpcMetadataAsValue(LLVMValueRef raw) { +PymMetadataAsValue* getMoreSpcMetadataAsValue(LLVMValueRef raw) { if (auto v = LLVMIsAMDNode(raw)) { - return new PyMDNodeValue(v); + return new PymMDNodeValue(v); } else if (auto v = LLVMIsAMDString(raw)) { - return new PyMDStringValue(v); + return new PymMDStringValue(v); } - return new PyMetadataAsValue(raw); + return new PymMetadataAsValue(raw); } @@ -20,70 +20,70 @@ PyMetadataAsValue* getMoreSpcMetadataAsValue(LLVMValueRef raw) { * * @param Inst: should be of LLVMInstructionValueKind */ -PyInstruction* PyInstructionAuto(LLVMValueRef inst) { +PymInstruction* PymInstructionAuto(LLVMValueRef inst) { LLVMOpcode opcode = LLVMGetInstructionOpcode(inst); switch (opcode) { case LLVMCall: - return new PyCallInst(inst); + return new PymCallInst(inst); case LLVMInvoke: - return new PyInvokeInst(inst); + return new PymInvokeInst(inst); case LLVMFCmp: - return new PyFCmpInst(inst); + return new PymFCmpInst(inst); case LLVMICmp: - return new PyICmpInst(inst); + return new PymICmpInst(inst); case LLVMGetElementPtr: - return new PyGetElementPtrInst(inst); + return new PymGetElementPtrInst(inst); case LLVMPHI: - return new PyPHINode(inst); + return new PymPHINode(inst); case LLVMShuffleVector: - return new PyShuffleVectorInst(inst); + return new PymShuffleVectorInst(inst); case LLVMRet: - return new PyReturnInst(inst); + return new PymReturnInst(inst); case LLVMSwitch: - return new PySwitchInst(inst); + return new PymSwitchInst(inst); case LLVMCatchSwitch: - return new PyCatchSwitchInst(inst); + return new PymCatchSwitchInst(inst); case LLVMCleanupRet: - return new PyCleanupReturnInst(inst); - // no kind corresponding to PyFuncletPadInst + return new PymCleanupReturnInst(inst); + // no kind corresponding to PymFuncletPadInst case LLVMCatchPad: - return new PyCatchPadInst(inst); + return new PymCatchPadInst(inst); case LLVMAlloca: - return new PyAllocaInst(inst); + return new PymAllocaInst(inst); case LLVMInsertValue: - return new PyInsertValueInst(inst); + return new PymInsertValueInst(inst); case LLVMExtractValue: - return new PyExtractValueInst(inst); + return new PymExtractValueInst(inst); case LLVMBr: - return new PyBranchInst(inst); + return new PymBranchInst(inst); case LLVMIndirectBr: - return new PyIndirectBrInst(inst); + return new PymIndirectBrInst(inst); case LLVMLandingPad: - return new PyLandingPadInst(inst); + return new PymLandingPadInst(inst); case LLVMLoad: - return new PyLoadInst(inst); + return new PymLoadInst(inst); case LLVMStore: - return new PyStoreInst(inst); + return new PymStoreInst(inst); case LLVMAtomicRMW: - return new PyAtomicRMWInst(inst); + return new PymAtomicRMWInst(inst); case LLVMAtomicCmpXchg: - return new PyAtomicCmpXchgInst(inst); + return new PymAtomicCmpXchgInst(inst); case LLVMFence: - return new PyFenceInst(inst); + return new PymFenceInst(inst); default: - return new PyInstruction(inst); + return new PymInstruction(inst); } } -PyType* PyTypeAuto(LLVMTypeRef rawType) { +PymType* PymTypeAuto(LLVMTypeRef rawType) { LLVMTypeKind kind = LLVMGetTypeKind(rawType); switch (kind) { case LLVMVoidTypeKind: - return new PyTypeVoid(rawType); + return new PymTypeVoid(rawType); case LLVMHalfTypeKind: case LLVMFloatTypeKind: case LLVMDoubleTypeKind: @@ -91,35 +91,35 @@ PyType* PyTypeAuto(LLVMTypeRef rawType) { case LLVMFP128TypeKind: case LLVMPPC_FP128TypeKind: case LLVMBFloatTypeKind: - return new PyTypeReal(rawType); + return new PymTypeReal(rawType); case LLVMLabelTypeKind: - return new PyTypeLabel(rawType); + return new PymTypeLabel(rawType); case LLVMIntegerTypeKind: - return new PyTypeInt(rawType); + return new PymTypeInt(rawType); case LLVMFunctionTypeKind: - return new PyTypeFunction(rawType); + return new PymTypeFunction(rawType); case LLVMStructTypeKind: - return new PyTypeStruct(rawType); + return new PymTypeStruct(rawType); case LLVMArrayTypeKind: - return new PyTypeArray(rawType); + return new PymTypeArray(rawType); case LLVMPointerTypeKind: - return new PyTypePointer(rawType); + return new PymTypePointer(rawType); case LLVMVectorTypeKind: - return new PyTypeVector(rawType); + return new PymTypeVector(rawType); case LLVMMetadataTypeKind: - return new PyTypeMetadata(rawType); + return new PymTypeMetadata(rawType); case LLVMX86_MMXTypeKind: - return new PyTypeX86MMX(rawType); + return new PymTypeX86MMX(rawType); case LLVMTokenTypeKind: - return new PyTypeToken(rawType); + return new PymTypeToken(rawType); case LLVMScalableVectorTypeKind: - return new PyTypeVector(rawType); + return new PymTypeVector(rawType); case LLVMX86_AMXTypeKind: - return new PyTypeX86AMX(rawType); + return new PymTypeX86AMX(rawType); case LLVMTargetExtTypeKind: - return new PyTypeTargetExt(rawType); + return new PymTypeTargetExt(rawType); default: - return new PyType(rawType); + return new PymType(rawType); } } @@ -127,78 +127,78 @@ PyType* PyTypeAuto(LLVMTypeRef rawType) { * It seems like the enum type doesn't cover all the sub-classes, * so user may still need to do a manual cast using `to_XXX` method */ -PyValue* PyValueAuto(LLVMValueRef rawValue) { +PymValue* PymValueAuto(LLVMValueRef rawValue) { LLVMValueKind kind = LLVMGetValueKind(rawValue); switch (kind) { case LLVMArgumentValueKind: - return new PyArgument(rawValue); + return new PymArgument(rawValue); case LLVMBasicBlockValueKind: - return new PyBasicBlockValue(rawValue); + return new PymBasicBlockValue(rawValue); // case LLVMMemoryUseValueKind: // case LLVMMemoryDefValueKind: // case LLVMMemoryPhiValueKind: case LLVMFunctionValueKind: - return new PyFunction(rawValue); + return new PymFunction(rawValue); case LLVMGlobalAliasValueKind: - return new PyGlobalAlias(rawValue); + return new PymGlobalAlias(rawValue); case LLVMGlobalIFuncValueKind: - return new PyGlobalIFunc(rawValue); + return new PymGlobalIFunc(rawValue); case LLVMGlobalVariableValueKind: - return new PyGlobalVariable(rawValue); + return new PymGlobalVariable(rawValue); // case LLVMBlockAddressValueKind: case LLVMConstantExprValueKind: - return new PyConstantExpr(rawValue); + return new PymConstantExpr(rawValue); case LLVMConstantArrayValueKind: - return new PyConstantArray(rawValue); + return new PymConstantArray(rawValue); case LLVMConstantStructValueKind: - return new PyConstantStruct(rawValue); + return new PymConstantStruct(rawValue); case LLVMConstantVectorValueKind: - return new PyConstantVector(rawValue); + return new PymConstantVector(rawValue); case LLVMUndefValueValueKind: - return new PyUndefValue(rawValue); + return new PymUndefValue(rawValue); case LLVMConstantDataArrayValueKind: - return new PyConstantDataArray(rawValue); + return new PymConstantDataArray(rawValue); case LLVMConstantDataVectorValueKind: - return new PyConstantDataVector(rawValue); + return new PymConstantDataVector(rawValue); case LLVMConstantIntValueKind: - return new PyConstantInt(rawValue); + return new PymConstantInt(rawValue); case LLVMConstantFPValueKind: - return new PyConstantFP(rawValue); + return new PymConstantFP(rawValue); case LLVMConstantTokenNoneValueKind: case LLVMConstantAggregateZeroValueKind: case LLVMConstantPointerNullValueKind: - return new PyConstant(rawValue); + return new PymConstant(rawValue); case LLVMMetadataAsValueValueKind: return getMoreSpcMetadataAsValue(rawValue); case LLVMInlineAsmValueKind: - return new PyInlineAsm(rawValue); + return new PymInlineAsm(rawValue); case LLVMInstructionValueKind: - return PyInstructionAuto(rawValue); + return PymInstructionAuto(rawValue); case LLVMPoisonValueValueKind: - return new PyPoisonValue(rawValue); + return new PymPoisonValue(rawValue); // case LLVMConstantTargetNoneValueKind: // default: - return new PyValue(rawValue); + return new PymValue(rawValue); } } -PyAttribute* PyAttributeAuto(LLVMAttributeRef rawValue) { +PymAttribute* PymAttributeAuto(LLVMAttributeRef rawValue) { if (LLVMIsEnumAttribute(rawValue)) { - return new PyEnumAttribute(rawValue); + return new PymEnumAttribute(rawValue); } else if (LLVMIsStringAttribute(rawValue)) { - return new PyStringAttribute(rawValue); + return new PymStringAttribute(rawValue); } else if (LLVMIsTypeAttribute(rawValue)) { - return new PyTypeAttribute(rawValue); + return new PymTypeAttribute(rawValue); } else { - return new PyAttribute(rawValue); + return new PymAttribute(rawValue); } } -PyModule parseIR(LLVMContextRef ctx, LLVMMemoryBufferRef memBuf) { +PymModule parseIR(LLVMContextRef ctx, LLVMMemoryBufferRef memBuf) { LLVMModuleRef m = nullptr; char *errMsg = nullptr; bool success = LLVMParseIRInContext(ctx, memBuf, &m, &errMsg) == 0; @@ -211,5 +211,5 @@ PyModule parseIR(LLVMContextRef ctx, LLVMMemoryBufferRef memBuf) { throw std::runtime_error(errorMessage); } - return PyModule(m); + return PymModule(m); } diff --git a/src/llvm/Core/utils.h b/src/llvm/Core/utils.h index 9052760..d760151 100644 --- a/src/llvm/Core/utils.h +++ b/src/llvm/Core/utils.h @@ -16,9 +16,9 @@ inline const char *get_repr_str(T &&obj) { return nanobind::repr(nanobind::cast(obj)).c_str(); } -PyMetadataAsValue* getMoreSpcMetadataAsValue(LLVMValueRef raw); +PymMetadataAsValue* getMoreSpcMetadataAsValue(LLVMValueRef raw); -inline std::string get_type_str(PyType &t) { +inline std::string get_type_str(PymType &t) { char *str = LLVMPrintTypeToString(t.get()); std::string res(str); LLVMDisposeMessage(str); @@ -38,21 +38,21 @@ inline std::string get_value_name(LLVMValueRef v) { return std::string(str, len); } -inline std::string gen_value_repr(const char *typeName, PyValue &v) { +inline std::string gen_value_repr(const char *typeName, PymValue &v) { LLVMValueRef raw = v.get(); auto name = get_value_name(raw); return fmt::format("<{} name='{}'>", typeName, name); } -PyInstruction* PyInstructionAuto(LLVMValueRef inst); +PymInstruction* PymInstructionAuto(LLVMValueRef inst); -PyType* PyTypeAuto(LLVMTypeRef rawType); +PymType* PymTypeAuto(LLVMTypeRef rawType); -PyValue* PyValueAuto(LLVMValueRef rawValue); +PymValue* PymValueAuto(LLVMValueRef rawValue); -PyAttribute* PyAttributeAuto(LLVMAttributeRef rawValue); +PymAttribute* PymAttributeAuto(LLVMAttributeRef rawValue); -PyModule parseIR(LLVMContextRef ctx, LLVMMemoryBufferRef memBuf); +PymModule parseIR(LLVMContextRef ctx, LLVMMemoryBufferRef memBuf); #endif diff --git a/src/llvm/Core/value.cpp b/src/llvm/Core/value.cpp index b132a8b..e834c30 100644 --- a/src/llvm/Core/value.cpp +++ b/src/llvm/Core/value.cpp @@ -19,104 +19,104 @@ using optional = std::optional; void bindValueClasses(nb::module_ &m) { - auto ValueClass = nb::class_> + auto ValueClass = nb::class_> (m, "Value", "Value"); - nb::class_(m, "MetadataAsValue", "MetadataAsValue"); - auto MDNodeValueClass = nb::class_ + nb::class_(m, "MetadataAsValue", "MetadataAsValue"); + auto MDNodeValueClass = nb::class_ (m, "MDNodeValue", "MDNodeValue"); - auto ValueAsMetadataValueClass = nb::class_ + auto ValueAsMetadataValueClass = nb::class_ (m, "ValueAsMetadataValue", "ValueAsMetadataValue"); - auto MDStringValueClass = nb::class_ + auto MDStringValueClass = nb::class_ (m, "MDStringValue", "MDStringValue"); - auto ArgumentClass = nb::class_(m, "Argument", "Argument"); - auto BasicBlockValueClass = nb::class_(m, "BasicBlockValue", "BasicBlockValue"); - auto InlineAsmClass = nb::class_(m, "InlineAsm", "InlineAsm"); - auto UserClass = nb::class_(m, "User", "User"); - auto ConstantClass = nb::class_(m, "Constant", "Constant"); - auto ConstantArrayClass = nb::class_(m, "ConstantArray", "ConstantArray"); - auto ConstantDataSequentialClass = nb::class_ + auto ArgumentClass = nb::class_(m, "Argument", "Argument"); + auto BasicBlockValueClass = nb::class_(m, "BasicBlockValue", "BasicBlockValue"); + auto InlineAsmClass = nb::class_(m, "InlineAsm", "InlineAsm"); + auto UserClass = nb::class_(m, "User", "User"); + auto ConstantClass = nb::class_(m, "Constant", "Constant"); + auto ConstantArrayClass = nb::class_(m, "ConstantArray", "ConstantArray"); + auto ConstantDataSequentialClass = nb::class_ (m, "ConstantDataSequential", "ConstantDataSequential"); - auto ConstantDataArrayClass = nb::class_ + auto ConstantDataArrayClass = nb::class_ (m, "ConstantDataArray", "ConstantDataArray"); - auto ConstantDataVectorClass = nb::class_ + auto ConstantDataVectorClass = nb::class_ (m, "ConstantDataVector", "ConstantDataVector"); - auto ConstantExprClass = nb::class_(m, "ConstantExpr", "ConstantExpr"); - auto ConstantFPClass = nb::class_(m, "ConstantFP", "ConstantFP"); - auto ConstantIntClass = nb::class_(m, "ConstantInt", "ConstantInt"); - auto ConstantStructClass = nb::class_(m, "ConstantStruct", "ConstantStruct"); - auto ConstantVectorClass = nb::class_(m, "ConstantVector", "ConstantVector"); - auto GlobalValueClass = nb::class_(m, "GlobalValue", "GlobalValue"); - auto GlobalAliasClass = nb::class_(m, "GlobalAlias", "GlobalAlias"); - auto GlobalObjectClass = nb::class_(m, "GlobalObject", "GlobalObject"); - auto FunctionClass = nb::class_(m, "Function", "Function"); - auto GlobalVariableClass = nb::class_(m, "GlobalVariable", "GlobalVariable"); - auto GlobalIFuncClass = nb::class_(m, "GlobalIFunc", "GlobalIFunc"); - auto UndefValueClass = nb::class_(m, "UndefValue", "UndefValue"); - auto PoisonValueClass = nb::class_(m, "PoisonValue", "PoisonValue"); - auto InstructionClass = nb::class_(m, "Instruction", "Instruction"); - auto CallBaseClass = nb::class_(m, "CallBase", "CallBase"); - auto CallInstClass = nb::class_(m, "CallInst", "CallInst"); - auto InvokeInstClass = nb::class_(m, "InvokeInst", "InvokeInst"); - auto FCmpInstClass = nb::class_(m, "FCmpInst", "FCmpInst"); - auto ICmpInstClass = nb::class_(m, "ICmpInst", "ICmpInst"); - auto GetElementPtrInstClass = nb::class_(m, "GetElementPtrInst", "GetElementPtrInst"); - auto PHINodeClass = nb::class_(m, "PHINode", "PHINode"); - auto ShuffleVectorInstClass = nb::class_(m, "ShuffleVectorInst", "ShuffleVectorInst"); - auto StoreInstClass = nb::class_(m, "StoreInst", "StoreInst"); - auto BranchInstClass = nb::class_(m, "BranchInst", "BranchInst"); - auto ReturnInstClass = nb::class_(m, "ReturnInst", "ReturnInst"); - auto SwitchInstClass = nb::class_(m, "SwitchInst", "SwitchInst"); - auto CatchSwitchInstClass = nb::class_ + auto ConstantExprClass = nb::class_(m, "ConstantExpr", "ConstantExpr"); + auto ConstantFPClass = nb::class_(m, "ConstantFP", "ConstantFP"); + auto ConstantIntClass = nb::class_(m, "ConstantInt", "ConstantInt"); + auto ConstantStructClass = nb::class_(m, "ConstantStruct", "ConstantStruct"); + auto ConstantVectorClass = nb::class_(m, "ConstantVector", "ConstantVector"); + auto GlobalValueClass = nb::class_(m, "GlobalValue", "GlobalValue"); + auto GlobalAliasClass = nb::class_(m, "GlobalAlias", "GlobalAlias"); + auto GlobalObjectClass = nb::class_(m, "GlobalObject", "GlobalObject"); + auto FunctionClass = nb::class_(m, "Function", "Function"); + auto GlobalVariableClass = nb::class_(m, "GlobalVariable", "GlobalVariable"); + auto GlobalIFuncClass = nb::class_(m, "GlobalIFunc", "GlobalIFunc"); + auto UndefValueClass = nb::class_(m, "UndefValue", "UndefValue"); + auto PoisonValueClass = nb::class_(m, "PoisonValue", "PoisonValue"); + auto InstructionClass = nb::class_(m, "Instruction", "Instruction"); + auto CallBaseClass = nb::class_(m, "CallBase", "CallBase"); + auto CallInstClass = nb::class_(m, "CallInst", "CallInst"); + auto InvokeInstClass = nb::class_(m, "InvokeInst", "InvokeInst"); + auto FCmpInstClass = nb::class_(m, "FCmpInst", "FCmpInst"); + auto ICmpInstClass = nb::class_(m, "ICmpInst", "ICmpInst"); + auto GetElementPtrInstClass = nb::class_(m, "GetElementPtrInst", "GetElementPtrInst"); + auto PHINodeClass = nb::class_(m, "PHINode", "PHINode"); + auto ShuffleVectorInstClass = nb::class_(m, "ShuffleVectorInst", "ShuffleVectorInst"); + auto StoreInstClass = nb::class_(m, "StoreInst", "StoreInst"); + auto BranchInstClass = nb::class_(m, "BranchInst", "BranchInst"); + auto ReturnInstClass = nb::class_(m, "ReturnInst", "ReturnInst"); + auto SwitchInstClass = nb::class_(m, "SwitchInst", "SwitchInst"); + auto CatchSwitchInstClass = nb::class_ (m, "CatchSwitchInst", "CatchSwitchInst"); - auto CleanupReturnInstClass = nb::class_ + auto CleanupReturnInstClass = nb::class_ (m, "CleanupReturnInst", "CleanupReturnInst"); - auto FuncletPadInstClass = nb::class_(m, "FuncletPadInst", "FuncletPadInst"); - auto CatchPadInstClass = nb::class_(m, "CatchPadInst", "CatchPadInst"); - auto AllocaInstClass = nb::class_(m, "AllocaInst", "AllocaInst"); - auto LoadInstClass = nb::class_(m, "LoadInst", "LoadInst"); - auto AtomicCmpXchgInstClass = nb::class_(m, "AtomicCmpXchgInst", "AtomicCmpXchgInst"); - auto AtomicRMWInstClass = nb::class_ + auto FuncletPadInstClass = nb::class_(m, "FuncletPadInst", "FuncletPadInst"); + auto CatchPadInstClass = nb::class_(m, "CatchPadInst", "CatchPadInst"); + auto AllocaInstClass = nb::class_(m, "AllocaInst", "AllocaInst"); + auto LoadInstClass = nb::class_(m, "LoadInst", "LoadInst"); + auto AtomicCmpXchgInstClass = nb::class_(m, "AtomicCmpXchgInst", "AtomicCmpXchgInst"); + auto AtomicRMWInstClass = nb::class_ (m, "AtomicRMWInst", "AtomicRMWInst"); - auto IEValueInstBaseClass = nb::class_ + auto IEValueInstBaseClass = nb::class_ (m, "IEValueInstBase", "IEValueInstBase"); - auto InsertValueInstClass = nb::class_ + auto InsertValueInstClass = nb::class_ (m, "InsertValueInst", "InsertValueInst"); - auto ExtractValueInstClass = nb::class_ + auto ExtractValueInstClass = nb::class_ (m, "ExtractValueInst", "ExtractValueInst"); - auto LandingPadInstClass = nb::class_ + auto LandingPadInstClass = nb::class_ (m, "LandingPadInst", "LandingPadInst"); - auto IndirectBrInstClass = nb::class_ + auto IndirectBrInstClass = nb::class_ (m, "IndirectBrInst", "IndirectBrInst"); - auto FenceInstClass = nb::class_ + auto FenceInstClass = nb::class_ (m, "FenceInst", "FenceInst"); MDNodeValueClass .def("__repr__", - [](PyMDNodeValue &self) { + [](PymMDNodeValue &self) { return gen_value_repr("MDNodeValue", self); }) // deprecated functions not binded: // LLVMMDNodeInContext, LLVMMDNode .def("as_metadata", - [](PyMDStringValue &self) { - return PyMDNode(LLVMValueAsMetadata(self.get())); + [](PymMDStringValue &self) { + return PymMDNode(LLVMValueAsMetadata(self.get())); }) .def_prop_ro("num_operands", - [](PyMDNodeValue &self) { + [](PymMDNodeValue &self) { return LLVMGetMDNodeNumOperands(self.get()); }) .def_prop_ro("operands", - [](PyMDNodeValue &self) { + [](PymMDNodeValue &self) { unsigned num = LLVMGetMDNodeNumOperands(self.get()); std::vector dest(num); LLVMGetMDNodeOperands(self.get(), dest.data()); - WRAP_VECTOR_FROM_DEST_AUTO(PyValue, num, res, dest); + WRAP_VECTOR_FROM_DEST_AUTO(PymValue, num, res, dest); return res; }, "Obtain the given MDNode's operands.") .def_prop_ro("replace_operand_with", - [](PyMDNodeValue &self, unsigned index, PyMetadata &replacement) { + [](PymMDNodeValue &self, unsigned index, PymMetadata &replacement) { return LLVMReplaceMDNodeOperandWith (self.get(), index, replacement.get()); }, @@ -124,17 +124,17 @@ void bindValueClasses(nb::module_ &m) { MDStringValueClass .def("__repr__", - [](PyMDStringValue &self) { + [](PymMDStringValue &self) { return gen_value_repr("MDStringValue", self); }) // deprecated functions not binded: // LLVMMDStringInContext, LLVMMDString .def("as_metadata", - [](PyMDStringValue &self) { - return PyMDString(LLVMValueAsMetadata(self.get())); + [](PymMDStringValue &self) { + return PymMDString(LLVMValueAsMetadata(self.get())); }) .def_prop_ro("raw_string", - [](PyMDStringValue &v) { + [](PymMDStringValue &v) { unsigned len; auto str = LLVMGetMDString(v.get(), &len); return std::string(str, len); @@ -144,7 +144,7 @@ void bindValueClasses(nb::module_ &m) { ValueClass // TODO note there are many functions here that belongs `UserClass` .def("__repr__", - [](PyValue &self) { + [](PymValue &self) { auto raw = self.get(); auto name = get_value_name(raw); auto kind = get_repr_str(LLVMGetValueKind(raw)); @@ -152,87 +152,87 @@ void bindValueClasses(nb::module_ &m) { name, kind, get_value_str(raw)); }) .def("__str__", - [](PyValue &self) { + [](PymValue &self) { return get_value_str(self.get()); }) .def_prop_ro("type", - [](PyValue &v) { return PyTypeAuto(LLVMTypeOf(v.get())); }) + [](PymValue &v) { return PymTypeAuto(LLVMTypeOf(v.get())); }) .def_prop_ro("kind", - [](PyValue &v) { return LLVMGetValueKind(v.get()); }) + [](PymValue &v) { return LLVMGetValueKind(v.get()); }) // NOTE LLVMSetValueName and LLVMGetValueName are depreciated .def_prop_rw("name", - [](PyValue &v) { + [](PymValue &v) { return get_value_name(v.get()); }, - [](PyValue &v, std::string &name) { + [](PymValue &v, std::string &name) { return LLVMSetValueName2(v.get(), name.c_str(), name.size()); }) .def_prop_ro("is_constant", - [](PyValue &v) { return LLVMIsConstant(v.get()) != 0; }) + [](PymValue &v) { return LLVMIsConstant(v.get()) != 0; }) .def_prop_ro("is_undef", - [](PyValue &v) { return LLVMIsUndef(v.get()) != 0; }) + [](PymValue &v) { return LLVMIsUndef(v.get()) != 0; }) .def_prop_ro("is_poisonous", - [](PyValue &v) { return LLVMIsPoison(v.get()) != 0;}) + [](PymValue &v) { return LLVMIsPoison(v.get()) != 0;}) .def_prop_ro("first_use", - [](PyValue &v) -> optional { + [](PymValue &v) -> optional { auto res = LLVMGetFirstUse(v.get()); - WRAP_OPTIONAL_RETURN(res, PyUse); + WRAP_OPTIONAL_RETURN(res, PymUse); }) .def_prop_ro("uses", - [](PyValue &self) { - return PyUseIterator(PyUse(LLVMGetFirstUse(self.get()))); + [](PymValue &self) { + return PymUseIterator(PymUse(LLVMGetFirstUse(self.get()))); }) .def("as_metadata", - [](PyValue &self) { - return PyValueAsMetadata(LLVMValueAsMetadata(self.get())); + [](PymValue &self) { + return PymValueAsMetadata(LLVMValueAsMetadata(self.get())); }) .def("dump", - [](PyValue &v) { return LLVMDumpValue(v.get()); }, + [](PymValue &v) { return LLVMDumpValue(v.get()); }, "Dump a representation of a value to stderr.") .def_static("replace_all_uses_with", - [](PyValue &oldVal, PyValue &newVal) { + [](PymValue &oldVal, PymValue &newVal) { return LLVMReplaceAllUsesWith(oldVal.get(), newVal.get()); }, "Replace all uses of a value with another one.") PY_FOR_EACH_VALUE_SUBCLASS(PY_DECLARE_VALUE_CAST) .def("to_BasicBlockValue", - [](PyValue &self) -> optional { + [](PymValue &self) -> optional { auto res = LLVMIsABasicBlock(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlockValue); + WRAP_OPTIONAL_RETURN(res, PymBasicBlockValue); }) .def("to_MDNodeValue", - [](PyValue &self) -> optional { + [](PymValue &self) -> optional { auto res = LLVMIsAMDNode(self.get()); - WRAP_OPTIONAL_RETURN(res, PyMDNodeValue); + WRAP_OPTIONAL_RETURN(res, PymMDNodeValue); }) .def("to_ValueAsMetadataValue", - [](PyValue &self) -> optional { + [](PymValue &self) -> optional { auto res = LLVMIsAValueAsMetadata(self.get()); - WRAP_OPTIONAL_RETURN(res, PyValueAsMetadataValue); + WRAP_OPTIONAL_RETURN(res, PymValueAsMetadataValue); }) .def("to_MDStringValue", - [](PyValue &self) -> optional { + [](PymValue &self) -> optional { auto res = LLVMIsAMDString(self.get()); - WRAP_OPTIONAL_RETURN(res, PyMDStringValue); + WRAP_OPTIONAL_RETURN(res, PymMDStringValue); }) // TODO test whether these property are only true to BasicBlockValue .def_prop_ro("is_basic_block", - [](PyValue &self) { + [](PymValue &self) { return LLVMValueIsBasicBlock(self.get()) != 0; }) .def("as_basic_block", - [](PyValue &self) { - return PyBasicBlock(LLVMValueAsBasicBlock(self.get())); + [](PymValue &self) { + return PymBasicBlock(LLVMValueAsBasicBlock(self.get())); }); PoisonValueClass .def("__repr__", - [](PyPoisonValue &self) { + [](PymPoisonValue &self) { return gen_value_repr("PoisonValue", self); }) .def("__init__", - [](PyPoisonValue *p, PyType &t) { - new (p) PyPoisonValue(LLVMGetPoison(t.get())); + [](PymPoisonValue *p, PymType &t) { + new (p) PymPoisonValue(LLVMGetPoison(t.get())); }, "type"_a, "Obtain a constant value referring to a poison value of a type."); @@ -240,13 +240,13 @@ void bindValueClasses(nb::module_ &m) { UndefValueClass .def("__repr__", - [](PyUndefValue &self) { + [](PymUndefValue &self) { return gen_value_repr("UndefValue", self); }) .def("__init__", - [](PyUndefValue *uv, PyType &t) { - new (uv) PyUndefValue(LLVMGetUndef(t.get())); + [](PymUndefValue *uv, PymType &t) { + new (uv) PymUndefValue(LLVMGetUndef(t.get())); }, "type"_a, "Obtain a constant value referring to an undefined value of a type."); @@ -254,21 +254,21 @@ void bindValueClasses(nb::module_ &m) { ShuffleVectorInstClass .def("__repr__", - [](PyShuffleVectorInst &self) { + [](PymShuffleVectorInst &self) { return ""; }) .def_prop_ro("mask_elems_num", - [](PyShuffleVectorInst &self) { + [](PymShuffleVectorInst &self) { return LLVMGetNumMaskElements(self.get()); }) .def_static("get_undef_mask_elem", - [](PyShuffleVectorInst &self) { + [](PymShuffleVectorInst &self) { return LLVMGetUndefMaskElem(); }, "returns a constant that specifies that the result of a " "ShuffleVectorInst is undefined.") .def("get_mask_value", - [](PyValue &self, unsigned index) { + [](PymValue &self, unsigned index) { return LLVMGetMaskValue(self.get(), index); }, "index"_a, @@ -280,14 +280,14 @@ void bindValueClasses(nb::module_ &m) { CatchPadInstClass .def("__repr__", - [](PyCatchPadInst &self) { + [](PymCatchPadInst &self) { return ""; }) .def_prop_rw("parent", - [](PyCatchPadInst &self) { - return PyCatchSwitchInst(LLVMGetParentCatchSwitch(self.get())); + [](PymCatchPadInst &self) { + return PymCatchSwitchInst(LLVMGetParentCatchSwitch(self.get())); }, - [](PyCatchPadInst &self, PyCatchSwitchInst catchSwitch) { + [](PymCatchPadInst &self, PymCatchSwitchInst catchSwitch) { return LLVMSetParentCatchSwitch(self.get(), catchSwitch.get()); }); @@ -296,35 +296,35 @@ void bindValueClasses(nb::module_ &m) { GlobalIFuncClass .def("__repr__", - [](PyGlobalIFunc &self) { + [](PymGlobalIFunc &self) { return ""; }) .def_prop_ro("next", - [](PyGlobalIFunc &self) -> optional { + [](PymGlobalIFunc &self) -> optional { auto res = LLVMGetNextGlobalIFunc(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalIFunc); + WRAP_OPTIONAL_RETURN(res, PymGlobalIFunc); }) .def_prop_ro("prev", - [](PyGlobalIFunc &self) -> optional { + [](PymGlobalIFunc &self) -> optional { auto res = LLVMGetPreviousGlobalIFunc(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalIFunc); + WRAP_OPTIONAL_RETURN(res, PymGlobalIFunc); }) .def_prop_rw("resolver", - [](PyGlobalIFunc &self) -> optional { + [](PymGlobalIFunc &self) -> optional { auto res = LLVMGetGlobalIFuncResolver(self.get()); - WRAP_OPTIONAL_RETURN(res, PyConstant); + WRAP_OPTIONAL_RETURN(res, PymConstant); }, - [](PyGlobalIFunc &self, PyConstant resolver) { + [](PymGlobalIFunc &self, PymConstant resolver) { return LLVMSetGlobalIFuncResolver(self.get(), resolver.get()); }) .def("destory", - [](PyGlobalIFunc &self) { + [](PymGlobalIFunc &self) { return LLVMEraseGlobalIFunc(self.get()); }, "Remove a global indirect function from its parent module and delete it.\n\n" "You shouldn't use it anymore after removal.") .def("remove_from_parent", - [](PyGlobalIFunc &self) { + [](PymGlobalIFunc &self) { return LLVMRemoveGlobalIFunc(self.get()); }, "Remove a global indirect function from its parent module.\n\n" @@ -333,14 +333,14 @@ void bindValueClasses(nb::module_ &m) { InlineAsmClass .def("__repr__", - [](PyInlineAsm &self) { + [](PymInlineAsm &self) { return ""; }) .def("get_inline_asm", - [](PyInlineAsm *iasm, PyType &ty, std::string asmString, std::string constraints, + [](PymInlineAsm *iasm, PymType &ty, std::string asmString, std::string constraints, bool hasSideEffects, bool isAlignStack, LLVMInlineAsmDialect dialect, bool canThrow){ - new (iasm) PyInlineAsm(LLVMGetInlineAsm + new (iasm) PymInlineAsm(LLVMGetInlineAsm (ty.get(), asmString.c_str(), asmString.size(), constraints.c_str(), constraints.size(), hasSideEffects, isAlignStack, dialect, canThrow)); @@ -349,52 +349,52 @@ void bindValueClasses(nb::module_ &m) { "is_align_stack"_a, "dialect"_a, "can_throw"_a, "Create the specified unique inline asm string.") .def_prop_ro("str", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { size_t len; const char *str = LLVMGetInlineAsmAsmString(iasm.get(), &len); return std::string(str, len); }, "Get the template string used for an inline assembly snippet.") .def_prop_ro("constraint_str", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { size_t len; const char *str = LLVMGetInlineAsmConstraintString(iasm.get(), &len); return std::string(str, len); }, "Get the raw constraint string for an inline assembly snippet.") .def_prop_ro("dialect", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { return LLVMGetInlineAsmDialect(iasm.get()); }, "Get the dialect used by the inline asm snippet.") .def_prop_ro("function_type", - [](PyInlineAsm &iasm) { - return PyTypeFunction(LLVMGetInlineAsmFunctionType(iasm.get())); + [](PymInlineAsm &iasm) { + return PymTypeFunction(LLVMGetInlineAsmFunctionType(iasm.get())); }, "Get the function type of the inline assembly snippet. " "The same type that was passed into :func:`get_inline_asm` originally.") .def_prop_ro("has_side_effects", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { return LLVMGetInlineAsmHasSideEffects(iasm.get()) != 0; }, "Get if the inline asm snippet has side effects.") .def_prop_ro("needs_aligned_stack", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { return LLVMGetInlineAsmNeedsAlignedStack(iasm.get()) != 0; }) .def_prop_ro("can_unwind", - [](PyInlineAsm &iasm) { + [](PymInlineAsm &iasm) { return LLVMGetInlineAsmCanUnwind(iasm.get()) != 0; }); InstructionClass .def("__repr__", - [](PyInstruction &self) { + [](PymInstruction &self) { auto opcode = LLVMGetInstructionOpcode(self.get()); return fmt::format("", get_repr_str(opcode)); }) .def_prop_ro("can_use_fast_math_flags", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMCanValueUseFastMathFlags(self.get()) != 0; }, "Check if a given value can potentially have fast math flags.\n" @@ -403,106 +403,106 @@ void bindValueClasses(nb::module_ &m) { "point type, or a vector or array thereof.\n" "See https://llvm.org/docs/LangRef.html#fast-math-flags") .def_prop_ro("next", - [](PyInstruction &self) -> optional { + [](PymInstruction &self) -> optional { auto res = LLVMGetNextInstruction(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstruction); + WRAP_OPTIONAL_RETURN(res, PymInstruction); }, "Obtain the instruction that occurs after the one specified.\n" "The next instruction will be from the same basic block.\n\n" "If this is the last instruction in a basic block, None will " "be returned.") .def_prop_ro("prev", - [](PyInstruction &self) -> optional { + [](PymInstruction &self) -> optional { auto res = LLVMGetPreviousInstruction(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstruction); + WRAP_OPTIONAL_RETURN(res, PymInstruction); }, "Obtain the instruction that occurred before this one.\n\n" "If the instruction is the first instruction in a basic block, NULL" "will be returned.") .def_prop_ro("has_metadata", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMHasMetadata(self.get()) != 0; }) .def_prop_ro("debug_loc_directory", - [](PyInstruction &i) { + [](PymInstruction &i) { unsigned len; const char *res = LLVMGetDebugLocDirectory(i.get(), &len); return std::string(res, len); }, "Return the directory of the debug location for this value") .def_prop_ro("debug_loc_filename", - [](PyInstruction &i) { + [](PymInstruction &i) { unsigned len; const char *res = LLVMGetDebugLocFilename(i.get(), &len); return std::string(res, len); }, "Return the filename of the debug location for this value.") .def_prop_ro("debug_loc_line", - [](PyInstruction &i) { return LLVMGetDebugLocLine(i.get()); }, + [](PymInstruction &i) { return LLVMGetDebugLocLine(i.get()); }, "Return the line number of the debug location for this value") .def_prop_ro("debug_loc_column", - [](PyInstruction &i) { return LLVMGetDebugLocColumn(i.get()); }, + [](PymInstruction &i) { return LLVMGetDebugLocColumn(i.get()); }, "Return the column number of the debug location for this value") .def_prop_ro("parent", - [](PyInstruction &self) -> optional { + [](PymInstruction &self) -> optional { auto res = LLVMGetInstructionParent(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlock); + WRAP_OPTIONAL_RETURN(res, PymBasicBlock); }, "Obtain the basic block to which an instruction belongs.") .def_prop_ro("opcode", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMGetInstructionOpcode(self.get()); }) .def_prop_ro("is_terminator", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMIsATerminatorInst(self.get()) != nullptr; }) .def("clone", - [](PyInstruction &self) -> optional { + [](PymInstruction &self) -> optional { auto res = LLVMInstructionClone(self.get()); - WRAP_OPTIONAL_RETURN(res, PyInstructionAuto); + WRAP_OPTIONAL_RETURN(res, PymInstructionAuto); }, "Create a copy of 'this' instruction that is identical in all ways" "except the following:\n" " - The instruction has no parent" " - The instruction has no name") .def("remove_from_parent", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMInstructionRemoveFromParent(self.get()); }, "The instruction specified is removed from its containing building" "block but is kept alive.") .def("destory", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMInstructionEraseFromParent(self.get()); }, "Remove and delete an instruction.\n\n" "The instruction specified is removed from its containing building" "block and then deleted.") .def("delete", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMDeleteInstruction(self.get()); }, "Delete an instruction.\n\n" "The instruction specified is deleted. It must have previously been" "removed from its containing building block.") .def("get_metadata", - [](PyInstruction &self, unsigned kindID) -> optional { + [](PymInstruction &self, unsigned kindID) -> optional { auto res = LLVMGetMetadata(self.get(), kindID); - WRAP_OPTIONAL_RETURN(res, PyValueAuto); + WRAP_OPTIONAL_RETURN(res, PymValueAuto); }, "kind_id"_a) .def("set_metadata", - [](PyInstruction &self, unsigned kindID, PyMetadataAsValue node) { + [](PymInstruction &self, unsigned kindID, PymMetadataAsValue node) { return LLVMSetMetadata(self.get(), kindID, node.get()); }, "kind_id"_a, "value"_a) .def("get_all_metadata_no_debug_loc", - [](PyInstruction &self) { + [](PymInstruction &self) { size_t num; LLVMValueMetadataEntries entries = LLVMInstructionGetAllMetadataOtherThanDebugLoc(self.get(), &num); - return PyMetadataEntries(entries, num); + return PymMetadataEntries(entries, num); }) /* The following methods only applys to instructions for which LLVMIsATerminatorInst @@ -517,64 +517,64 @@ void bindValueClasses(nb::module_ &m) { */ .def_prop_ro("successors_num", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMGetNumSuccessors(self.get()); }) .def("get_successor", - [](PyInstruction &self, unsigned index) { - return PyBasicBlock(LLVMGetSuccessor(self.get(), index)); + [](PymInstruction &self, unsigned index) { + return PymBasicBlock(LLVMGetSuccessor(self.get(), index)); }) .def("set_successor", - [](PyInstruction &self, unsigned index, PyBasicBlock bb) { + [](PymInstruction &self, unsigned index, PymBasicBlock bb) { return LLVMSetSuccessor(self.get(), index, bb.get()); }) // TODO .def_static("get_nuw", - [](PyInstruction &arithInst) { + [](PymInstruction &arithInst) { return LLVMGetNUW(arithInst.get()) != 0; }, "arith_inst"_a) .def_static("set_nuw", - [](PyInstruction &arithInst, bool hasNUW) { + [](PymInstruction &arithInst, bool hasNUW) { return LLVMSetNUW(arithInst.get(), hasNUW); }, "arith_inst"_a, "hasNUW"_a) .def_static("get_nsw", - [](PyInstruction &arithInst) { + [](PymInstruction &arithInst) { return LLVMGetNSW(arithInst.get()) != 0; }, "arithInst"_a) .def_static("set_nsw", - [](PyInstruction &arithInst, bool hasNSW) { + [](PymInstruction &arithInst, bool hasNSW) { return LLVMSetNSW(arithInst.get(), hasNSW); }, "arith_inst"_a, "hasNSW"_a) .def_static("get_exact", - [](PyInstruction &DivOrShrInst) { + [](PymInstruction &DivOrShrInst) { return LLVMGetExact(DivOrShrInst.get()) != 0; }, "div_or_shr_inst"_a) .def_static("set_exact", - [](PyInstruction &DivOrShrInst, bool isExact) { + [](PymInstruction &DivOrShrInst, bool isExact) { return LLVMSetExact(DivOrShrInst.get(), isExact); }, "div_or_shr_inst"_a, "is_exact"_a) .def_static("get_nneg", - [](PyInstruction &NonNegInst) { + [](PymInstruction &NonNegInst) { return LLVMGetNNeg(NonNegInst.get()) != 0; }, "non_neg_inst"_a, "Gets if the instruction has the non-negative flag set.\n", "Only valid for zext instructions.") .def_static("set_nned", - [](PyInstruction &NonNegInst, bool isNonNeg) { + [](PymInstruction &NonNegInst, bool isNonNeg) { return LLVMSetNNeg(NonNegInst.get(), isNonNeg); }, "non_neg_inst"_a, "is_non_neg"_a, "Sets the non-negative flag for the instruction.\n" "Only valid for zext instructions.") .def_static("get_fast_math_flags", - [](PyInstruction &FPMathInst) { + [](PymInstruction &FPMathInst) { return LLVMGetFastMathFlags(FPMathInst.get()); }, "fp_math_inst"_a, @@ -583,7 +583,7 @@ void bindValueClasses(nb::module_ &m) { "Only valid on floating point instructions." "See `can_use_fast_math_flags`.") .def_static("set_fast_math_flags", - [](PyInstruction &FPMathInst, LLVMFastMathFlags FMF) { + [](PymInstruction &FPMathInst, LLVMFastMathFlags FMF) { return LLVMSetFastMathFlags(FPMathInst.get(), FMF); }, "fp_math_inst"_a, "fmf"_a, @@ -592,14 +592,14 @@ void bindValueClasses(nb::module_ &m) { "Only valid on floating point instructions.\n" "See `can_use_fast_math_flags`.") .def_static("get_is_disjoint", - [](PyInstruction &inst) { + [](PymInstruction &inst) { return LLVMGetIsDisjoint(inst.get()) != 0; }, "inst"_a, "Gets whether the instruction has the disjoint flag set.\n" "Only valid for or instructions.") .def_static("set_is_disjoint", - [](PyInstruction &inst, bool isDisjoint) { + [](PymInstruction &inst, bool isDisjoint) { return LLVMSetIsDisjoint(inst.get(), isDisjoint); }, "inst"_a, "is_disjoint"_a, @@ -612,290 +612,290 @@ void bindValueClasses(nb::module_ &m) { BranchInstClass .def_prop_ro("is_conditional", - [](PyBranchInst &self) { + [](PymBranchInst &self) { return LLVMIsConditional(self.get()); }) .def_prop_rw("condition", // TODO test whether return NULL - [](PyBranchInst &self) { - return PyValueAuto(LLVMGetCondition(self.get())); + [](PymBranchInst &self) { + return PymValueAuto(LLVMGetCondition(self.get())); }, - [](PyBranchInst &self, PyValue &cond) { + [](PymBranchInst &self, PymValue &cond) { return LLVMSetCondition(self.get(), cond.get()); }); SwitchInstClass .def("__repr__", - [](PySwitchInst &self) { + [](PymSwitchInst &self) { return ""; }) .def_prop_ro("default_dest", - [](PySwitchInst &self) { - return PyBasicBlock(LLVMGetSwitchDefaultDest(self.get())); + [](PymSwitchInst &self) { + return PymBasicBlock(LLVMGetSwitchDefaultDest(self.get())); }) .def_prop_ro("add_case", - [](PySwitchInst &self, PyConstantInt &onVal, PyBasicBlock dest) { + [](PymSwitchInst &self, PymConstantInt &onVal, PymBasicBlock dest) { return LLVMAddCase(self.get(), onVal.get(), dest.get()); }); IEValueInstBaseClass .def_prop_ro("indices_num", - [](PyIEValueInstBase &self) { + [](PymIEValueInstBase &self) { return LLVMGetNumIndices(self.get()); }) .def("indices", - [](PyIEValueInstBase &self) { + [](PymIEValueInstBase &self) { return LLVMGetIndices(self.get()); }); CallInstClass .def_prop_rw("is_tail_call", - [](PyCallInst &self) { + [](PymCallInst &self) { return LLVMIsTailCall(self.get()) != 0; }, - [](PyCallInst &self, bool isTailCall) { + [](PymCallInst &self, bool isTailCall) { return LLVMSetTailCall(self.get(), isTailCall); }) .def_prop_rw("tail_call_kind", - [](PyCallInst &self) { + [](PymCallInst &self) { return LLVMGetTailCallKind(self.get()); }, - [](PyCallInst &self, LLVMTailCallKind kind) { + [](PymCallInst &self, LLVMTailCallKind kind) { return LLVMSetTailCallKind(self.get(), kind); }); CallBaseClass .def_prop_ro("arg_num", - [](PyCallBase &self) { + [](PymCallBase &self) { return LLVMGetNumArgOperands(self.get()); }) .def_prop_rw("call_conv", - [](PyCallBase &self) { + [](PymCallBase &self) { auto res = LLVMGetInstructionCallConv(self.get()); return static_cast(res); }, - [](PyCallBase &self, LLVMCallConv CC) { + [](PymCallBase &self, LLVMCallConv CC) { return LLVMSetInstructionCallConv(self.get(), CC); }) .def_prop_ro("called_fn_type", - [](PyCallBase &self) { - return PyTypeFunction(LLVMGetCalledFunctionType(self.get())); + [](PymCallBase &self) { + return PymTypeFunction(LLVMGetCalledFunctionType(self.get())); }, "Obtain the function type called by this instruction.") .def_prop_ro("called_value", - [](PyCallBase &self) { - return PyFunction(LLVMGetCalledValue(self.get())); + [](PymCallBase &self) { + return PymFunction(LLVMGetCalledValue(self.get())); }) .def_prop_ro("operand_bundles_num", - [](PyCallBase &self) { + [](PymCallBase &self) { return LLVMGetNumOperandBundles(self.get()); }) .def("get_operand_bundle_at", - [](PyCallBase &self, unsigned index) { - return PyOperandBundle(LLVMGetOperandBundleAtIndex(self.get(), index)); + [](PymCallBase &self, unsigned index) { + return PymOperandBundle(LLVMGetOperandBundleAtIndex(self.get(), index)); }, "index"_a, "Obtain the operand bundle attached to this instruction at the given index.") .def("set_arg_alignment", - [](PyCallBase &self, LLVMAttributeIndex idx, unsigned align) { + [](PymCallBase &self, LLVMAttributeIndex idx, unsigned align) { return LLVMSetInstrParamAlignment(self.get(), idx, align); }, "index"_a, "align"_a) .def("add_call_site_attribute", - [](PyCallBase &self, LLVMAttributeIndex idx, PyAttribute &attr) { + [](PymCallBase &self, LLVMAttributeIndex idx, PymAttribute &attr) { return LLVMAddCallSiteAttribute(self.get(), idx, attr.get()); }, "index"_a, "attr"_a) .def("get_call_site_attribute_count", - [](PyCallBase &self, LLVMAttributeIndex idx) { + [](PymCallBase &self, LLVMAttributeIndex idx) { return LLVMGetCallSiteAttributeCount(self.get(), idx); }) .def("get_call_site_attributes", - [](PyCallBase &self, LLVMAttributeIndex idx) { + [](PymCallBase &self, LLVMAttributeIndex idx) { unsigned num = LLVMGetCallSiteAttributeCount(self.get(), idx); std::vector attrs(num); LLVMGetCallSiteAttributes(self.get(), idx, attrs.data()); - WRAP_VECTOR_FROM_DEST_AUTO(PyAttribute, num, res, attrs); + WRAP_VECTOR_FROM_DEST_AUTO(PymAttribute, num, res, attrs); return res; }) .def("get_call_site_enum_attribute", - [](PyCallBase &self, LLVMAttributeIndex idx, unsigned kindID) { - return PyEnumAttribute(LLVMGetCallSiteEnumAttribute(self.get(), idx, + [](PymCallBase &self, LLVMAttributeIndex idx, unsigned kindID) { + return PymEnumAttribute(LLVMGetCallSiteEnumAttribute(self.get(), idx, kindID)); }) .def("get_call_site_string_attribute", - [](PyCallBase &self, LLVMAttributeIndex idx, std::string &kind) { - return PyStringAttribute(LLVMGetCallSiteStringAttribute + [](PymCallBase &self, LLVMAttributeIndex idx, std::string &kind) { + return PymStringAttribute(LLVMGetCallSiteStringAttribute (self.get(), idx, kind.c_str(), kind.size())); }) .def("remove_call_site_enum_attribute", - [](PyCallBase &self, LLVMAttributeIndex idx, unsigned kindID) { + [](PymCallBase &self, LLVMAttributeIndex idx, unsigned kindID) { return LLVMRemoveCallSiteEnumAttribute(self.get(), idx, kindID); }) .def("remove_call_site_string_attribute", - [](PyCallBase &self, LLVMAttributeIndex idx, std::string &kind) { + [](PymCallBase &self, LLVMAttributeIndex idx, std::string &kind) { return LLVMRemoveCallSiteStringAttribute (self.get(), idx, kind.c_str(), kind.size()); }); InvokeInstClass .def("__repr__", - [](PyInvokeInst &self) { + [](PymInvokeInst &self) { return ""; }) .def_prop_rw("normal_dest", - [](PyInvokeInst &self) { - return PyBasicBlock(LLVMGetNormalDest(self.get())); + [](PymInvokeInst &self) { + return PymBasicBlock(LLVMGetNormalDest(self.get())); }, - [](PyInvokeInst &self, PyBasicBlock bb) { + [](PymInvokeInst &self, PymBasicBlock bb) { return LLVMSetNormalDest(self.get(), bb.get()); }) .def_prop_rw("unwind_dest", - [](PyInvokeInst &self) { - return PyBasicBlock(LLVMGetUnwindDest(self.get())); + [](PymInvokeInst &self) { + return PymBasicBlock(LLVMGetUnwindDest(self.get())); }, - [](PyInvokeInst &self, PyBasicBlock bb) { + [](PymInvokeInst &self, PymBasicBlock bb) { return LLVMSetUnwindDest(self.get(), bb.get()); }); CleanupReturnInstClass .def("__repr__", - [](PyCleanupReturnInst &self) { + [](PymCleanupReturnInst &self) { return ""; }) .def_prop_rw("unwind_dest", - [](PyCleanupReturnInst &self) { - return PyBasicBlock(LLVMGetUnwindDest(self.get())); + [](PymCleanupReturnInst &self) { + return PymBasicBlock(LLVMGetUnwindDest(self.get())); }, - [](PyCleanupReturnInst &self, PyBasicBlock bb) { + [](PymCleanupReturnInst &self, PymBasicBlock bb) { return LLVMSetUnwindDest(self.get(), bb.get()); }); CatchSwitchInstClass .def("__repr__", - [](PyCatchSwitchInst &self) { + [](PymCatchSwitchInst &self) { return ""; }) .def_prop_rw("unwind_dest", - [](PyCatchSwitchInst &self) { - return PyBasicBlock(LLVMGetUnwindDest(self.get())); + [](PymCatchSwitchInst &self) { + return PymBasicBlock(LLVMGetUnwindDest(self.get())); }, - [](PyCatchSwitchInst &self, PyBasicBlock bb) { + [](PymCatchSwitchInst &self, PymBasicBlock bb) { return LLVMSetUnwindDest(self.get(), bb.get()); }) .def_prop_ro("handlers_num", - [](PyCatchSwitchInst &self) { + [](PymCatchSwitchInst &self) { return LLVMGetNumHandlers(self.get()); }) .def_prop_ro("handlers", - [](PyCatchSwitchInst &self) { + [](PymCatchSwitchInst &self) { unsigned num = LLVMGetNumHandlers(self.get()); std::vector handlers; LLVMGetHandlers(self.get(), handlers.data()); - WRAP_VECTOR_FROM_DEST(PyBasicBlock, num, res, handlers); + WRAP_VECTOR_FROM_DEST(PymBasicBlock, num, res, handlers); return res; }, "Obtain the basic blocks acting as handlers for a catchswitch " "instruction.") .def("add_handler", - [](PyCatchSwitchInst &self, PyBasicBlock dest) { + [](PymCatchSwitchInst &self, PymBasicBlock dest) { return LLVMAddHandler(self.get(), dest.get()); }); FuncletPadInstClass .def("__repr__", - [](PyFuncletPadInst &self) { + [](PymFuncletPadInst &self) { return ""; }) .def_prop_ro("arg_num", - [](PyCallBase &self) { + [](PymCallBase &self) { // TODO change it into enum type return LLVMGetNumArgOperands(self.get()); }) .def("get_arg_operand", - [](PyFuncletPadInst &self, unsigned index) { - return PyValueAuto(LLVMGetArgOperand(self.get(), index)); + [](PymFuncletPadInst &self, unsigned index) { + return PymValueAuto(LLVMGetArgOperand(self.get(), index)); }, "index"_a) .def("set_arg_operand", - [](PyFuncletPadInst &self, unsigned index, PyValue &value) { + [](PymFuncletPadInst &self, unsigned index, PymValue &value) { return LLVMSetArgOperand(self.get(), index, value.get()); }); ICmpInstClass .def("__repr__", - [](PyICmpInst &self) { + [](PymICmpInst &self) { return ""; }) .def_prop_ro("predicate", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMGetICmpPredicate(self.get()); }, "Obtain the predicate of an instruction."); FCmpInstClass .def("__repr__", - [](PyFCmpInst &self) { + [](PymFCmpInst &self) { return ""; }) .def_prop_ro("predicate", - [](PyInstruction &self) { + [](PymInstruction &self) { return LLVMGetFCmpPredicate(self.get()); }, "Obtain the float predicate of an instruction."); GlobalVariableClass .def("__repr__", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return gen_value_repr("GlobalVariable", self); }) .def("__init__", - [](PyGlobalVariable *g, PyModule &m, PyType &type, const char *name) { - new (g) PyGlobalVariable(LLVMAddGlobal(m.get(), type.get(), name)); + [](PymGlobalVariable *g, PymModule &m, PymType &type, const char *name) { + new (g) PymGlobalVariable(LLVMAddGlobal(m.get(), type.get(), name)); }, "module"_a, "type"_a, "name"_a = "") .def_prop_rw("initializer", - [](PyGlobalVariable &self) { - return PyValueAuto(LLVMGetInitializer(self.get())); + [](PymGlobalVariable &self) { + return PymValueAuto(LLVMGetInitializer(self.get())); }, - [](PyGlobalVariable &self, PyConstant &c) { + [](PymGlobalVariable &self, PymConstant &c) { return LLVMSetInitializer(self.get(), c.get()); }, nb::for_setter(nb::sig("def initializer(self, value: Constant) -> None"))) .def_prop_rw("is_thread_local", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return LLVMIsThreadLocal(self.get()) != 0; }, - [](PyGlobalVariable &self, bool isThreadLocal) { + [](PymGlobalVariable &self, bool isThreadLocal) { return LLVMSetThreadLocal(self.get(), isThreadLocal); }) .def_prop_rw("is_global_constant", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return LLVMIsGlobalConstant(self.get()) != 0; }, - [](PyGlobalVariable &self, bool isConstant) { + [](PymGlobalVariable &self, bool isConstant) { return LLVMSetGlobalConstant(self.get(), isConstant); }, nb::for_setter (nb::sig ("def is_global_constant(self, is_constant: bool, /) -> None"))) .def_prop_rw("thread_local_mode", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return LLVMGetThreadLocalMode(self.get()); }, - [](PyGlobalVariable &self, LLVMThreadLocalMode mode) { + [](PymGlobalVariable &self, LLVMThreadLocalMode mode) { return LLVMSetThreadLocalMode(self.get(), mode); }, nb::for_setter (nb::sig("def thread_local_mode(self, mode: ThreadLocalMode, /) " "-> None"))) .def_prop_rw("is_externally_initialized", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return LLVMIsExternallyInitialized(self.get()) != 0; }, - [](PyGlobalVariable &self, bool isExtInit) { + [](PymGlobalVariable &self, bool isExtInit) { return LLVMSetExternallyInitialized(self.get(), isExtInit); }, nb::for_setter @@ -903,36 +903,36 @@ void bindValueClasses(nb::module_ &m) { ("def is_externally_initialized(self, is_ext_init: bool, /)" " -> None"))) .def_prop_ro("next", - [](PyGlobalVariable &v) -> std::optional { + [](PymGlobalVariable &v) -> std::optional { auto res = LLVMGetNextGlobal(v.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalVariable); + WRAP_OPTIONAL_RETURN(res, PymGlobalVariable); }) .def_prop_ro("prev", - [](PyGlobalVariable &v) -> std::optional { + [](PymGlobalVariable &v) -> std::optional { auto res = LLVMGetPreviousGlobal(v.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalVariable); + WRAP_OPTIONAL_RETURN(res, PymGlobalVariable); }) .def_prop_ro("debug_loc_directory", - [](PyGlobalVariable &v) { + [](PymGlobalVariable &v) { unsigned len; const char *res = LLVMGetDebugLocDirectory(v.get(), &len); return std::string(res, len); }, "Return the directory of the debug location for this value") .def_prop_ro("debug_loc_filename", - [](PyGlobalVariable &v) { + [](PymGlobalVariable &v) { unsigned len; const char *res = LLVMGetDebugLocFilename(v.get(), &len); return std::string(res, len); }, "Return the filename of the debug location for this value") .def_prop_ro("debug_loc_line", - [](PyGlobalVariable &v) { return LLVMGetDebugLocLine(v.get()); }, + [](PymGlobalVariable &v) { return LLVMGetDebugLocLine(v.get()); }, "Return the line number of the debug location for this value") // TODO test + more suitable way? (python side also do `del v`?) // but python pass variable by value... .def("destory", - [](PyGlobalVariable &self) { + [](PymGlobalVariable &self) { return LLVMDeleteGlobal(self.get()); }, "Delete this variable. You are not supposed to use this variable later."); @@ -941,171 +941,171 @@ void bindValueClasses(nb::module_ &m) { GlobalAliasClass .def("__repr__", - [](PyGlobalAlias &self) { + [](PymGlobalAlias &self) { return gen_value_repr("GlobalAlias", self); }) .def("__init__", - [](PyGlobalAlias *g, PyModule &self, PyType &valueType, unsigned addrSpace, - PyValue aliasee, const char *name) { - new (g) PyGlobalAlias(LLVMAddAlias2 + [](PymGlobalAlias *g, PymModule &self, PymType &valueType, unsigned addrSpace, + PymValue aliasee, const char *name) { + new (g) PymGlobalAlias(LLVMAddAlias2 (self.get(), valueType.get(), addrSpace, aliasee.get(), name)); }, "module"_a, "value_type"_a, "addr_space"_a, "aliasee"_a, "name"_a = "", "Add a GlobalAlias with the given value type, address space and aliasee.") .def_prop_ro("next", - [](PyGlobalAlias &self) -> std::optional { + [](PymGlobalAlias &self) -> std::optional { auto res = LLVMGetNextGlobalAlias(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalAlias); + WRAP_OPTIONAL_RETURN(res, PymGlobalAlias); }, "Advance a GlobalAlias iterator to the next GlobalAlias.\n\n" "Returns NULL if the iterator was already at the beginning and there are" "no previous global aliases.") .def_prop_ro("prev", - [](PyGlobalAlias &self) -> std::optional { + [](PymGlobalAlias &self) -> std::optional { auto res = LLVMGetPreviousGlobalAlias(self.get()); - WRAP_OPTIONAL_RETURN(res, PyGlobalAlias); + WRAP_OPTIONAL_RETURN(res, PymGlobalAlias); }, "Decrement a GlobalAlias iterator to the previous GlobalAlias.\n\n" "Returns NULL if the iterator was already at the beginning and there are" "no previous global aliases.") .def_prop_rw("aliasee", - [](PyGlobalAlias &self) { - return PyValueAuto(LLVMAliasGetAliasee(self.get())); + [](PymGlobalAlias &self) { + return PymValueAuto(LLVMAliasGetAliasee(self.get())); }, - [](PyGlobalAlias &self, PyValue &aliasee) { + [](PymGlobalAlias &self, PymValue &aliasee) { return LLVMAliasSetAliasee(self.get(), aliasee.get()); }); FunctionClass .def("__repr__", - [](PyFunction &self) { + [](PymFunction &self) { return gen_value_repr("Function", self); }) .def("__init__", - [](PyFunction *f, PyModule &m, PyTypeFunction &functionTy, std::string &name) { - new (f) PyFunction(LLVMAddFunction(m.get(), name.c_str(), functionTy.get())); + [](PymFunction *f, PymModule &m, PymTypeFunction &functionTy, std::string &name) { + new (f) PymFunction(LLVMAddFunction(m.get(), name.c_str(), functionTy.get())); }, "module"_a, "function_type"_a, "name"_a = "", "Add a function to a module under a specified name.") .def_prop_rw("call_conv", - [](PyFunction &self){ + [](PymFunction &self){ auto res = LLVMGetFunctionCallConv(self.get()); return static_cast(res); }, - [](PyFunction &self, LLVMCallConv CC) { + [](PymFunction &self, LLVMCallConv CC) { return LLVMSetFunctionCallConv(self.get(), CC); }) .def_prop_rw("gc", - [](PyFunction &self) { + [](PymFunction &self) { return LLVMGetGC(self.get()); }, - [](PyFunction &self, const char *name) { + [](PymFunction &self, const char *name) { return LLVMSetGC(self.get(), name); }, nb::for_getter ("Obtain the name of the garbage collector to use " "during code generation.")) .def_prop_ro("basic_blocks_num", - [](PyFunction &self) { + [](PymFunction &self) { return LLVMCountBasicBlocks(self.get()); }) .def_prop_ro("basic_blocks", - [](PyFunction &self) { + [](PymFunction &self) { unsigned num = LLVMCountBasicBlocks(self.get()); std::vector BasicBlocks(num); LLVMGetBasicBlocks(self.get(), BasicBlocks.data()); - WRAP_VECTOR_FROM_DEST(PyBasicBlock, num, + WRAP_VECTOR_FROM_DEST(PymBasicBlock, num, res, BasicBlocks); return res; }) .def_prop_ro("first_basic_block", - [](PyFunction &self) -> optional { + [](PymFunction &self) -> optional { auto res = LLVMGetFirstBasicBlock(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlock); + WRAP_OPTIONAL_RETURN(res, PymBasicBlock); }) .def_prop_ro("last_basic_block", - [](PyFunction &self) -> optional { + [](PymFunction &self) -> optional { auto res = LLVMGetLastBasicBlock(self.get()); - WRAP_OPTIONAL_RETURN(res, PyBasicBlock); + WRAP_OPTIONAL_RETURN(res, PymBasicBlock); }) .def_prop_ro("entry_basic_block", - [](PyFunction &self) { - return PyBasicBlock(LLVMGetEntryBasicBlock(self.get())); + [](PymFunction &self) { + return PymBasicBlock(LLVMGetEntryBasicBlock(self.get())); }) .def_prop_ro("has_personality_fn", - [](PyFunction &self) { + [](PymFunction &self) { return LLVMHasPersonalityFn(self.get()) != 0; }) .def_prop_rw("personality_fn", - [](PyFunction &self) { - return PyFunction(LLVMGetPersonalityFn(self.get())); + [](PymFunction &self) { + return PymFunction(LLVMGetPersonalityFn(self.get())); }, - [](PyFunction &self, PyFunction fn) { + [](PymFunction &self, PymFunction fn) { return LLVMSetPersonalityFn(self.get(), fn.get()); }) .def_prop_ro("intrinsic_id", - [](PyFunction &self) { + [](PymFunction &self) { return LLVMGetIntrinsicID(self.get()); }) .def_prop_ro("next", - [](PyFunction &f) -> std::optional { + [](PymFunction &f) -> std::optional { auto res = LLVMGetNextFunction(f.get()); - WRAP_OPTIONAL_RETURN(res, PyFunction); + WRAP_OPTIONAL_RETURN(res, PymFunction); }, "Advance a Function iterator to the next Function.\n\n" "Returns NULL if the iterator was already at the end and there are no more" "functions.") .def_prop_ro("previous", - [](PyFunction &f) -> std::optional { + [](PymFunction &f) -> std::optional { auto res = LLVMGetPreviousFunction(f.get()); - WRAP_OPTIONAL_RETURN(res, PyFunction); + WRAP_OPTIONAL_RETURN(res, PymFunction); }, "Decrement a Function iterator to the previous Function.\n\n" "Returns NULL if the iterator was already at the beginning and there are" "no previous functions.") .def_prop_ro("debug_loc_directory", - [](PyFunction &f) { + [](PymFunction &f) { unsigned len; const char *res = LLVMGetDebugLocDirectory(f.get(), &len); return std::string(res, len); }, "Return the directory of the debug location for this value") .def_prop_ro("debug_loc_filename", - [](PyFunction &f) { + [](PymFunction &f) { unsigned len; const char *res = LLVMGetDebugLocFilename(f.get(), &len); return std::string(res, len); }, "Return the filename of the debug location for this value") .def_prop_ro("debug_loc_line", - [](PyFunction &f) { return LLVMGetDebugLocLine(f.get()); }, + [](PymFunction &f) { return LLVMGetDebugLocLine(f.get()); }, "Return the line number of the debug location for this value") .def_prop_ro("arg_num", - [](PyFunction &self) { + [](PymFunction &self) { return LLVMCountParams(self.get()); }) .def_prop_ro("first_arg", - [](PyFunction &self) -> optional { + [](PymFunction &self) -> optional { auto res = LLVMGetFirstParam(self.get()); - WRAP_OPTIONAL_RETURN(res, PyArgument); + WRAP_OPTIONAL_RETURN(res, PymArgument); }) .def_prop_ro("last_arg", - [](PyFunction &self) -> optional { + [](PymFunction &self) -> optional { auto res = LLVMGetLastParam(self.get()); - WRAP_OPTIONAL_RETURN(res, PyArgument); + WRAP_OPTIONAL_RETURN(res, PymArgument); }) .def_prop_ro("args", - [](PyFunction &self) { + [](PymFunction &self) { unsigned param_num = LLVMCountParams(self.get()); std::vector params(param_num); LLVMGetParams(self.get(), params.data()); - WRAP_VECTOR_FROM_DEST(PyArgument, param_num, res, params); + WRAP_VECTOR_FROM_DEST(PymArgument, param_num, res, params); return res; }) .def("verify", - [](PyFunction &self, LLVMVerifierFailureAction action) -> optional{ + [](PymFunction &self, LLVMVerifierFailureAction action) -> optional{ char *outMsg; auto res = LLVMVerifyFunction(self.get(), action) == 0; if (!res) { @@ -1122,73 +1122,73 @@ void bindValueClasses(nb::module_ &m) { "Verifies that a single function is valid, taking the specified action. Usefu" "for debugging.") .def("get_arg", - [](PyFunction &self, unsigned index) { - return PyArgument(LLVMGetParam(self.get(), index)); + [](PymFunction &self, unsigned index) { + return PymArgument(LLVMGetParam(self.get(), index)); }, "index"_a, "Obtain the parameter at the specified index.\n\n" "Parameters are indexed from 0.") .def("destory", // TODO test - [](PyFunction &self) { + [](PymFunction &self) { return LLVMDeleteFunction(self.get()); }, "Remove a function from its containing module and deletes it.\n\n" "Note you shouldn't use the the variable afterwards!") .def("add_attribute_at_index", - [](PyFunction &self, LLVMAttributeIndex idx, PyAttribute attr) { + [](PymFunction &self, LLVMAttributeIndex idx, PymAttribute attr) { return LLVMAddAttributeAtIndex(self.get(), idx, attr.get()); }, "index"_a, "attr"_a) .def("append_existing_basic_block", - [](PyFunction &self, PyBasicBlock bb) { + [](PymFunction &self, PymBasicBlock bb) { return LLVMAppendExistingBasicBlock(self.get(), bb.get()); }, "basic_block"_a, "Append the given basic block to the basic block list of the given function.") .def("append_basic_block", - [](PyFunction &self, const char *name) { - return PyBasicBlock(LLVMAppendBasicBlock(self.get(), name)); + [](PymFunction &self, const char *name) { + return PymBasicBlock(LLVMAppendBasicBlock(self.get(), name)); }, "name"_a = "", "Append a basic block to the end of a function using the global context.") .def("get_attribute_count_at_index", - [](PyFunction &self, LLVMAttributeIndex idx) { + [](PymFunction &self, LLVMAttributeIndex idx) { return LLVMGetAttributeCountAtIndex(self.get(), idx); }, "index"_a) .def("get_attributes_at_index", - [](PyFunction &self, LLVMAttributeIndex idx) { + [](PymFunction &self, LLVMAttributeIndex idx) { unsigned cnt = LLVMGetAttributeCountAtIndex(self.get(), idx); std::vector attrs(cnt); LLVMGetAttributesAtIndex(self.get(), idx, attrs.data()); - WRAP_VECTOR_FROM_DEST_AUTO(PyAttribute, cnt, res, attrs); + WRAP_VECTOR_FROM_DEST_AUTO(PymAttribute, cnt, res, attrs); return res; }, "index"_a) .def("get_enum_attribute_at_index", - [](PyFunction &self, LLVMAttributeIndex idx, unsigned kindID) { - return PyEnumAttribute(LLVMGetEnumAttributeAtIndex(self.get(), idx, kindID)); + [](PymFunction &self, LLVMAttributeIndex idx, unsigned kindID) { + return PymEnumAttribute(LLVMGetEnumAttributeAtIndex(self.get(), idx, kindID)); }, "index"_a, "kind"_a) .def("get_string_attribute_at_index", - [](PyFunction &self, LLVMAttributeIndex idx, std::string &kind) { - return PyStringAttribute(LLVMGetStringAttributeAtIndex + [](PymFunction &self, LLVMAttributeIndex idx, std::string &kind) { + return PymStringAttribute(LLVMGetStringAttributeAtIndex (self.get(), idx, kind.c_str(), kind.size())); }, "index"_a, "kind"_a) .def("remove_enum_attribute_at_index", - [](PyFunction &self, LLVMAttributeIndex idx, unsigned kindID) { + [](PymFunction &self, LLVMAttributeIndex idx, unsigned kindID) { return LLVMRemoveEnumAttributeAtIndex(self.get(), idx, kindID); }, "index"_a, "kind"_a) .def("remove_string_attribute_at_index", - [](PyFunction &self, LLVMAttributeIndex idx, std::string &kind) { + [](PymFunction &self, LLVMAttributeIndex idx, std::string &kind) { return LLVMRemoveStringAttributeAtIndex (self.get(), idx, kind.c_str(), kind.size()); }, "index"_a, "kind"_a) .def("add_target_dependent_attr", - [](PyFunction &self, const char *A, const char *V) { + [](PymFunction &self, const char *A, const char *V) { return LLVMAddTargetDependentFunctionAttr(self.get(), A, V); }, "A"_a, "V"_a, @@ -1196,101 +1196,101 @@ void bindValueClasses(nb::module_ &m) { ArgumentClass .def("__repr__", - [](PyArgument &self) { + [](PymArgument &self) { return gen_value_repr("Argument", self); }) .def_prop_ro("parent", - [](PyArgument &self) { - return PyFunction(LLVMGetParamParent(self.get())); + [](PymArgument &self) { + return PymFunction(LLVMGetParamParent(self.get())); }, "Obtain the function to which this argument belongs.") .def_prop_ro("next", - [](PyArgument &self) -> std::optional { + [](PymArgument &self) -> std::optional { auto res = LLVMGetNextParam(self.get()); - WRAP_OPTIONAL_RETURN(res, PyArgument); + WRAP_OPTIONAL_RETURN(res, PymArgument); }) .def_prop_ro("prev", - [](PyArgument &self) -> std::optional { + [](PymArgument &self) -> std::optional { auto res = LLVMGetPreviousParam(self.get()); - WRAP_OPTIONAL_RETURN(res, PyArgument); + WRAP_OPTIONAL_RETURN(res, PymArgument); }) .def("set_alignment", - [](PyArgument &self, unsigned Align) { + [](PymArgument &self, unsigned Align) { return LLVMSetParamAlignment(self.get(), Align); }); UserClass .def("__repr__", - [](PyUser &self) { + [](PymUser &self) { return gen_value_repr("User", self); }) .def("get_operand", - [](PyUser &u, unsigned index) { - return PyValueAuto(LLVMGetOperand(u.get(), index)); + [](PymUser &u, unsigned index) { + return PymValueAuto(LLVMGetOperand(u.get(), index)); }, "index"_a, "Obtain an operand at a specific index.") .def("get_operand_use", - [](PyUser &u, unsigned index) { - return PyUse(LLVMGetOperandUse(u.get(), index)); + [](PymUser &u, unsigned index) { + return PymUse(LLVMGetOperandUse(u.get(), index)); }, "Obtain the use of an operand at a specific index") .def("set_operand", - [](PyUser &u, unsigned index, PyValue &v) { + [](PymUser &u, unsigned index, PymValue &v) { return LLVMSetOperand(u.get(), index, v.get()); }, "index"_a, "value"_a, "Set an operand at a specific index") .def_prop_ro("operands_num", - [](PyUser &u) { + [](PymUser &u) { return LLVMGetNumOperands(u.get()); }); ConstantClass .def("__repr__", - [](PyConstant &self) { + [](PymConstant &self) { return gen_value_repr("Constant", self); }) // note these constructors are also available in TypeClass .def_static("null", - [](PyType &t) { - return PyValueAuto(LLVMConstNull(t.get())); + [](PymType &t) { + return PymValueAuto(LLVMConstNull(t.get())); }, "type"_a, "Obtain a constant value referring to the null instance of the type.") .def_static("pointer_null", - [](PyType &t) { - return PyValueAuto(LLVMConstPointerNull(t.get())); + [](PymType &t) { + return PymValueAuto(LLVMConstPointerNull(t.get())); }, "type"_a, "Obtain a constant that is a constant pointer pointing to NULL for the" "type.") .def_static("all_ones", - [](PyTypeInt &t) { - return PyValueAuto(LLVMConstAllOnes(t.get())); + [](PymTypeInt &t) { + return PymValueAuto(LLVMConstAllOnes(t.get())); }, "type"_a, "Obtain a constant value referring to the instance of the type" "consisting of all ones.") .def_static("undef", - [](PyType &t) { - return PyUndefValue(LLVMGetUndef(t.get())); + [](PymType &t) { + return PymUndefValue(LLVMGetUndef(t.get())); }, "type"_a, "Obtain a constant value referring to an undefined value of a type.") .def_static("poison", - [](PyType &t) { - return PyPoisonValue(LLVMGetPoison(t.get())); + [](PymType &t) { + return PymPoisonValue(LLVMGetPoison(t.get())); }, "type"_a, "Obtain a constant value referring to a poison value of a type.") .def_prop_ro("is_null", - [](PyConstant &c) { return LLVMIsNull(c.get()) != 0; }); + [](PymConstant &c) { return LLVMIsNull(c.get()) != 0; }); ConstantIntClass .def("__repr__", - [](PyConstantInt &self) { + [](PymConstantInt &self) { return gen_value_repr("ConstantInt", self); }) .def("__init__", - [](PyConstantInt *c, PyTypeInt &t, unsigned long long N, bool SignExtend) { - new (c) PyConstantInt(LLVMConstInt(t.get(), N, SignExtend)); + [](PymConstantInt *c, PymTypeInt &t, unsigned long long N, bool SignExtend) { + new (c) PymConstantInt(LLVMConstInt(t.get(), N, SignExtend)); }, "int_type"_a, "value"_a, "sign_extend"_a, "Original Function: LLVMConstInt.\n" @@ -1300,18 +1300,18 @@ void bindValueClasses(nb::module_ &m) { "value: The value the returned instance should refer to.\n" "sign_extend: Whether to sign extend the produced value.") .def("__init__", - [](PyConstantInt *c, PyTypeInt &t, unsigned NumWords, const uint64_t Words[]) { + [](PymConstantInt *c, PymTypeInt &t, unsigned NumWords, const uint64_t Words[]) { auto res = LLVMConstIntOfArbitraryPrecision (t.get(), NumWords, Words); - new (c) PyConstantInt(res); + new (c) PymConstantInt(res); }, "int_type"_a, "num_words"_a, "words"_a, "Origin Function: LLVMConstIntOfArbitraryPrecision.\n" "Obtain a constant value for an integer of arbitrary precision.") // LLVMConstIntOfString is discarded in favor of LLVMConstIntOfStringAndSize .def("__init__", - [](PyConstantInt *c, PyTypeInt &t, std::string &text, uint8_t Radix) { - new (c) PyConstantInt(LLVMConstIntOfStringAndSize + [](PymConstantInt *c, PymTypeInt &t, std::string &text, uint8_t Radix) { + new (c) PymConstantInt(LLVMConstIntOfStringAndSize (t.get(), text.c_str(), text.size(), Radix)); }, @@ -1319,39 +1319,39 @@ void bindValueClasses(nb::module_ &m) { "Original Function: LLVMConstIntOfStringAndSize\n" "Obtain a constant value for an integer parsed from a string.") .def_prop_ro("zext", - [](PyConstantInt &c) { + [](PymConstantInt &c) { return LLVMConstIntGetZExtValue(c.get()); }, "Obtain the zero extended value.") .def_prop_ro("sext", - [](PyConstantInt &c) { + [](PymConstantInt &c) { return LLVMConstIntGetSExtValue(c.get()); }, "Obtain the sign extended value."); ConstantFPClass .def("__repr__", - [](PyConstantFP &self) { + [](PymConstantFP &self) { return gen_value_repr("ConstantFP", self); }) .def("__init__", - [](PyConstantFP *c, PyTypeReal &t, double value) { - new (c) PyConstantFP(LLVMConstReal(t.get(), value)); + [](PymConstantFP *c, PymTypeReal &t, double value) { + new (c) PymConstantFP(LLVMConstReal(t.get(), value)); }, "real_type"_a, "value"_a, "Original Function: LLVMConstReal.\n" "Obtain a constant value referring to a double floating point value.\n\n") // LLVMConstRealOfString is discarded in favor of LLVMConstRealOfStringAndSize .def("__init__", - [](PyConstantFP *c, PyTypeReal &t, std::string text) { - new (c) PyConstantFP(LLVMConstRealOfStringAndSize + [](PymConstantFP *c, PymTypeReal &t, std::string text) { + new (c) PymConstantFP(LLVMConstRealOfStringAndSize (t.get(), text.c_str(), text.size())); }, "type"_a, "text"_a, "Original Function: LLVMConstRealOfStringAndSize\n" "Obtain a constant for a floating point value parsed from a string.") .def_prop_ro("double", - [](PyConstantFP &c) { + [](PymConstantFP &c) { LLVMBool losesInfo; double res = LLVMConstRealGetDouble(c.get(), &losesInfo); return std::make_tuple(res, losesInfo); @@ -1363,19 +1363,19 @@ void bindValueClasses(nb::module_ &m) { ConstantDataArrayClass .def("__repr__", - [](PyConstantDataArray &self) { + [](PymConstantDataArray &self) { return gen_value_repr("ConstantDataArray", self); }) .def("__str__", - [](PyConstantDataArray &c) { + [](PymConstantDataArray &c) { size_t len; auto str = LLVMGetAsString(c.get(), &len); return std::string(str, len); }, "Get the given constant data sequential as a string.") .def_static("create_string_in_context", - [](PyContext &cxt, std::string &str, bool DontNullTerminate) { - return PyConstantDataArray + [](PymContext &cxt, std::string &str, bool DontNullTerminate) { + return PymConstantDataArray (LLVMConstStringInContext (cxt.get(), str.c_str(), str.size(), DontNullTerminate)); @@ -1385,7 +1385,7 @@ void bindValueClasses(nb::module_ &m) { "with a string.") .def_static("create_string", [](std::string &str, bool DontNullTerminate) { - return PyConstantDataArray + return PymConstantDataArray (LLVMConstString (str.c_str(), str.size(), DontNullTerminate)); }, @@ -1393,12 +1393,12 @@ void bindValueClasses(nb::module_ &m) { "Create a ConstantDataSequential with string content" "in the global context.") .def_prop_ro("is_string", - [](PyConstantDataArray &c) { + [](PymConstantDataArray &c) { return LLVMIsConstantString(c.get()) != 0; }, "Returns true if the specified constant is an array of i8.") .def("as_string", - [](PyConstantDataArray &c) { + [](PymConstantDataArray &c) { size_t len; auto str = LLVMGetAsString(c.get(), &len); return std::string(str, len); @@ -1407,35 +1407,35 @@ void bindValueClasses(nb::module_ &m) { ConstantStructClass .def("__repr__", - [](PyConstantStruct &self) { + [](PymConstantStruct &self) { return gen_value_repr("ConstantStruct", self); }) .def("__init__", - [](PyConstantStruct *c, PyContext &cxt, - std::vector &vc, bool packed) { + [](PymConstantStruct *c, PymContext &cxt, + std::vector &vc, bool packed) { unsigned cnt = vc.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, vc, raw, cnt); - new (c) PyConstantStruct(LLVMConstStructInContext + new (c) PymConstantStruct(LLVMConstStructInContext (cxt.get(), raw.data(), cnt, packed)); }, "context"_a, "constant_values"_a, "packed"_a, "Create an anonymous ConstantStruct with the specified" "values.") .def("__init__", - [](PyConstantStruct *c, PyType &structTy, - std::vector &constantVals) { + [](PymConstantStruct *c, PymType &structTy, + std::vector &constantVals) { unsigned cnt = constantVals.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, constantVals, raw, cnt); - new (c) PyConstantStruct(LLVMConstNamedStruct(structTy.get(), + new (c) PymConstantStruct(LLVMConstNamedStruct(structTy.get(), raw.data(), cnt)); }, "struct_type"_a, "constant_values"_a, "Create a non-anonymous ConstantStruct from values.") .def("get_element_at", - [](PyConstantStruct &c, unsigned idx) -> std::optional{ + [](PymConstantStruct &c, unsigned idx) -> std::optional{ auto res = LLVMGetAggregateElement(c.get(), idx); - WRAP_OPTIONAL_RETURN(res, PyValueAuto); + WRAP_OPTIONAL_RETURN(res, PymValueAuto); }, "index"_a, "Returns null if the index is out of range, or it's not possible to " @@ -1445,24 +1445,24 @@ void bindValueClasses(nb::module_ &m) { ConstantArrayClass .def("__repr__", - [](PyConstantArray &self) { + [](PymConstantArray &self) { return gen_value_repr("ConstantArray", self); }) // LLVMConstArray is deprecated in favor of LLVMConstArray2 .def("__init__", - [](PyConstantArray *c, PyType &elemType, - std::vector ConstantVals) { + [](PymConstantArray *c, PymType &elemType, + std::vector ConstantVals) { uint64_t cnt = ConstantVals.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, ConstantVals, raw, cnt); - new (c) PyConstantArray(LLVMConstArray2(elemType.get(), + new (c) PymConstantArray(LLVMConstArray2(elemType.get(), raw.data(), cnt)); }, "elem_type"_a, "constant_vals"_a, "Create a ConstantArray from values.") .def("get_element_at", - [](PyConstantArray &c, unsigned idx) -> std::optional{ + [](PymConstantArray &c, unsigned idx) -> std::optional{ auto res = LLVMGetAggregateElement(c.get(), idx); - WRAP_OPTIONAL_RETURN(res, PyValueAuto); + WRAP_OPTIONAL_RETURN(res, PymValueAuto); }, "index"_a, "Returns null if the index is out of range, or it's not possible to " @@ -1471,20 +1471,20 @@ void bindValueClasses(nb::module_ &m) { ConstantVectorClass .def("__repr__", - [](PyConstantVector &self) { + [](PymConstantVector &self) { return gen_value_repr("ConstantVector", self); }) .def("__init__", - [](PyConstantVector *c, std::vector values) { + [](PymConstantVector *c, std::vector values) { auto cnt = values.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, values, raw, cnt); - new (c) PyConstantVector(LLVMConstVector(raw.data(), cnt)); + new (c) PymConstantVector(LLVMConstVector(raw.data(), cnt)); }, "values"_a) // LLVMGetElementAsConstant is deprecated in favor of LLVMGetAggregateElement .def("get_element_at", - [](PyConstantVector &c, unsigned idx) -> std::optional{ + [](PymConstantVector &c, unsigned idx) -> std::optional{ auto res = LLVMGetAggregateElement(c.get(), idx); - WRAP_OPTIONAL_RETURN(res, PyValueAuto); + WRAP_OPTIONAL_RETURN(res, PymValueAuto); }, "index"_a, "Returns null if the index is out of range, or it's not possible to " @@ -1494,145 +1494,145 @@ void bindValueClasses(nb::module_ &m) { ConstantExprClass .def("__repr__", - [](PyConstantExpr &self) { + [](PymConstantExpr &self) { return gen_value_repr("ConstantExpr", self); }) .def_prop_ro("opcode", - [](PyConstantExpr &c) { + [](PymConstantExpr &c) { return LLVMGetConstOpcode(c.get()); }, "value"_a) .def("get_icmp_predicate", // TODO test - [](PyConstantExpr &self) { + [](PymConstantExpr &self) { return LLVMGetICmpPredicate(self.get()); }, "Obtain the predicate of an instruction." "The opcode needs to be llvm::Instruction::ICmp.") .def("get_fcmp_predicate", // TODO test - [](PyConstantExpr &self) { + [](PymConstantExpr &self) { return LLVMGetFCmpPredicate(self.get()); }, "Obtain the float predicate of an instruction." "The opcode needs to be llvm::Instruction::FCmp.") .def_static("get_align_of", - [](PyType &t) { - return PyConstantExpr(LLVMAlignOf(t.get())); + [](PymType &t) { + return PymConstantExpr(LLVMAlignOf(t.get())); }, "type"_a) .def_static("get_size_of", - [](PyType &t) { - return PyConstantExpr(LLVMSizeOf(t.get())); + [](PymType &t) { + return PymConstantExpr(LLVMSizeOf(t.get())); }, "type"_a) .def_static("neg", - [](PyConstant &c) { - return PyValueAuto(LLVMConstNeg(c.get())); + [](PymConstant &c) { + return PymValueAuto(LLVMConstNeg(c.get())); }, "value"_a) .def_static("neg_nsw", // no signed wrap - [](PyConstant &c) { - return PyValueAuto(LLVMConstNSWNeg(c.get())); + [](PymConstant &c) { + return PymValueAuto(LLVMConstNSWNeg(c.get())); }, "value"_a, "LLVMConstNSWNeg") .def_static("neg_nuw", // no unsigned wrap - [](PyConstant &c) { - return PyValueAuto(LLVMConstNUWNeg(c.get())); + [](PymConstant &c) { + return PymValueAuto(LLVMConstNUWNeg(c.get())); }, "value"_a, "LLVMConstNUWNeg") .def_static("not_", - [](PyConstant &c) { - return PyValueAuto(LLVMConstNot(c.get())); + [](PymConstant &c) { + return PymValueAuto(LLVMConstNot(c.get())); }, "value"_a) CONSTANT_EXPR_BIND_BINARY_OPS .def_static("icmp", // test passing ConstantFP type values - [](LLVMIntPredicate predicate, PyConstant &lhs, PyConstant &rhs) { - return PyValueAuto(LLVMConstICmp(predicate, lhs.get(), rhs.get())); + [](LLVMIntPredicate predicate, PymConstant &lhs, PymConstant &rhs) { + return PymValueAuto(LLVMConstICmp(predicate, lhs.get(), rhs.get())); }, "predicate"_a, "lhs"_a, "rhs"_a) .def_static("fcmp", // test passing ConstantFP type values - [](LLVMRealPredicate predicate, PyConstant &lhs, PyConstant &rhs) { - return PyValueAuto(LLVMConstFCmp(predicate, lhs.get(), rhs.get())); + [](LLVMRealPredicate predicate, PymConstant &lhs, PymConstant &rhs) { + return PymValueAuto(LLVMConstFCmp(predicate, lhs.get(), rhs.get())); }, "predicate"_a, "lhs"_a, "rhs"_a) .def_static("gep2", - [](PyType &type, PyConstant &value, std::vector indices) { + [](PymType &type, PymConstant &value, std::vector indices) { unsigned num = indices.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, indices, raw, num); - return PyValueAuto(LLVMConstGEP2(type.get(), value.get(), raw.data(), + return PymValueAuto(LLVMConstGEP2(type.get(), value.get(), raw.data(), num)); }, "type"_a, "value"_a, "indices"_a) .def_static("gep2_in_bounds", - [](PyType &type, PyConstant &value, std::vector indices) { + [](PymType &type, PymConstant &value, std::vector indices) { unsigned num = indices.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, indices, raw, num); - return PyValueAuto(LLVMConstInBoundsGEP2(type.get(), value.get(), + return PymValueAuto(LLVMConstInBoundsGEP2(type.get(), value.get(), raw.data(), num)); }, "type"_a, "value"_a, "indices"_a) .def_static("trunc", - [](PyConstant &value, PyType &toType) { - return PyValueAuto(LLVMConstTrunc(value.get(), toType.get())); + [](PymConstant &value, PymType &toType) { + return PymValueAuto(LLVMConstTrunc(value.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("ptr2int", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstIntToPtr(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstIntToPtr(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("int2ptr", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstPtrToInt(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstPtrToInt(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("bit_cast", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstBitCast(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstBitCast(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("addr_space_cast", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstAddrSpaceCast(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstAddrSpaceCast(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("trunc_or_bit_cast", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstTruncOrBitCast(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstTruncOrBitCast(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("pointer_cast", - [](PyConstant &c, PyType &toType) { - return PyValueAuto(LLVMConstPointerCast(c.get(), toType.get())); + [](PymConstant &c, PymType &toType) { + return PymValueAuto(LLVMConstPointerCast(c.get(), toType.get())); }, "value"_a, "to_type"_a) .def_static("extract_element", // TODO test ConstantArray - [](PyConstantVector &vector, PyConstant &index) { - return PyValueAuto(LLVMConstExtractElement(vector.get(), index.get())); + [](PymConstantVector &vector, PymConstant &index) { + return PymValueAuto(LLVMConstExtractElement(vector.get(), index.get())); }, "vector"_a, "index"_a) .def_static("insert_element", - [](PyConstantVector &vector, PyConstant &index, PyConstant &value) { - return PyValueAuto(LLVMConstInsertElement(vector.get(), value.get(), + [](PymConstantVector &vector, PymConstant &index, PymConstant &value) { + return PymValueAuto(LLVMConstInsertElement(vector.get(), value.get(), index.get())); }, "vector"_a, "index"_a, "value"_a) .def_static("shuffle_vector", - [](PyConstantVector &vectorA, PyConstantVector &vectorB, - PyConstant &mask) { - return PyValueAuto(LLVMConstShuffleVector + [](PymConstantVector &vectorA, PymConstantVector &vectorB, + PymConstant &mask) { + return PymValueAuto(LLVMConstShuffleVector (vectorA.get(), vectorB.get(), mask.get())); }, "vector_a"_a, "vector_b"_a, "mask"_a) .def_static("block_address", - [](PyConstant &value, PyBasicBlock &bb) { + [](PymConstant &value, PymBasicBlock &bb) { // This instruction returns an BlockAddress kind value, which // isn't used elsewhere in LLVM C API - return PyValue(LLVMBlockAddress(value.get(), bb.get())); + return PymValue(LLVMBlockAddress(value.get(), bb.get())); }); @@ -1640,76 +1640,76 @@ void bindValueClasses(nb::module_ &m) { GlobalValueClass .def("__repr__", - [](PyGlobalValue &self) { + [](PymGlobalValue &self) { return gen_value_repr("GlobalValue", self); }) .def_prop_rw("alignment", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetAlignment(v.get()); }, - [](PyGlobalValue &v, unsigned Bytes) { + [](PymGlobalValue &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_ro("parent", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { auto res = LLVMGetGlobalParent(v.get()); - return PyModule(res); + return PymModule(res); }) .def_prop_ro("is_declaration", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMIsDeclaration(v.get()) != 0; }) .def_prop_rw("linkage", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetLinkage(v.get()); }, - [](PyGlobalValue &v, LLVMLinkage linkage) { + [](PymGlobalValue &v, LLVMLinkage linkage) { return LLVMSetLinkage(v.get(), linkage); }, nb::for_setter (nb::sig("def linkage(self, linkage: Linkage, /) -> None"))) .def_prop_rw("section", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetSection(v.get()); }, - [](PyGlobalValue &v, const char *Section) { + [](PymGlobalValue &v, const char *Section) { return LLVMSetSection(v.get(), Section); }, nb::for_setter (nb::sig("def section(self, section: str, /) -> None"))) .def_prop_rw("visibility", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetVisibility(v.get()); }, - [](PyGlobalValue &v, LLVMVisibility visibility) { + [](PymGlobalValue &v, LLVMVisibility visibility) { return LLVMSetVisibility(v.get(), visibility); }, nb::for_setter (nb::sig ("def visibility(self, visibility: Visibility, /) -> None"))) .def_prop_rw("dll_storage_class", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetDLLStorageClass(v.get()); }, - [](PyGlobalValue &v, LLVMDLLStorageClass cls) { + [](PymGlobalValue &v, LLVMDLLStorageClass cls) { return LLVMSetDLLStorageClass(v.get(), cls); }) // LLVMHasUnnamedAddr is deprecated in favor of LLVMGetUnnamedAddress // LLVMSetUnnamedAddr is deprecated in favor of LLVMSetUnnamedAddress .def_prop_rw("unnamed_address", - [](PyGlobalValue &v) { + [](PymGlobalValue &v) { return LLVMGetUnnamedAddress(v.get()); }, - [](PyGlobalValue &v, LLVMUnnamedAddr unnamedAddr) { + [](PymGlobalValue &v, LLVMUnnamedAddr unnamedAddr) { return LLVMSetUnnamedAddress(v.get(), unnamedAddr); }, nb::for_setter (nb::sig("def unnamed_address(self, addr: UnnamedAddr) -> None"))) .def_prop_ro("value_type", - [](PyGlobalValue &v) { - return PyTypeAuto(LLVMGlobalGetValueType(v.get())); + [](PymGlobalValue &v) { + return PymTypeAuto(LLVMGlobalGetValueType(v.get())); }, "Returns the \"value type\" of a global value. This differs " "from the formal type of a global value which is always a pointer" @@ -1718,57 +1718,57 @@ void bindValueClasses(nb::module_ &m) { AllocaInstClass .def("__repr__", - [](PyAllocaInst &self) { + [](PymAllocaInst &self) { return ""; }) .def_prop_rw("alignment", - [](PyAllocaInst &v) { + [](PymAllocaInst &v) { return LLVMGetAlignment(v.get()); }, - [](PyAllocaInst &v, unsigned Bytes) { + [](PymAllocaInst &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_ro("type", - [](PyAllocaInst &self) { - return PyTypeAuto(LLVMGetAllocatedType(self.get())); + [](PymAllocaInst &self) { + return PymTypeAuto(LLVMGetAllocatedType(self.get())); }); GetElementPtrInstClass .def("__repr__", - [](PyGetElementPtrInst &self) { + [](PymGetElementPtrInst &self) { return ""; }) .def_prop_ro("indices_num", - [](PyGetElementPtrInst &self) { + [](PymGetElementPtrInst &self) { return LLVMGetNumIndices(self.get()); }) .def_prop_rw("is_bounds", - [](PyGetElementPtrInst &self) { + [](PymGetElementPtrInst &self) { return LLVMIsInBounds(self.get()) != 0; }, - [](PyGetElementPtrInst &self, bool inBounds) { + [](PymGetElementPtrInst &self, bool inBounds) { return LLVMSetIsInBounds(self.get(), inBounds); }) .def_prop_ro("source_element_type", - [](PyGetElementPtrInst &self) { - return PyTypeAuto(LLVMGetGEPSourceElementType(self.get())); + [](PymGetElementPtrInst &self) { + return PymTypeAuto(LLVMGetGEPSourceElementType(self.get())); }); PHINodeClass .def("__repr__", - [](PyPHINode &self) { + [](PymPHINode &self) { return ""; }) .def_prop_ro("incoming_num", - [](PyPHINode &self) { + [](PymPHINode &self) { return LLVMCountIncoming(self.get()); }, "Obtain the number of incoming basic blocks to a PHI node.") .def("add_incoming", - [](PyPHINode &self, std::vector incomingValues, - std::vector incomingBlocks, unsigned Count) { + [](PymPHINode &self, std::vector incomingValues, + std::vector incomingBlocks, unsigned Count) { unsigned cnt = incomingValues.size(); UNWRAP_VECTOR_WRAPPER_CLASS(LLVMValueRef, incomingValues, rawValues, cnt); @@ -1778,237 +1778,237 @@ void bindValueClasses(nb::module_ &m) { cnt); }) .def("get_incoming_value", - [](PyPHINode &self, unsigned index) { - return PyValueAuto(LLVMGetIncomingValue(self.get(), index)); + [](PymPHINode &self, unsigned index) { + return PymValueAuto(LLVMGetIncomingValue(self.get(), index)); }) .def("get_incoming_block", - [](PyPHINode &self, unsigned index) { - return PyBasicBlock(LLVMGetIncomingBlock(self.get(), index)); + [](PymPHINode &self, unsigned index) { + return PymBasicBlock(LLVMGetIncomingBlock(self.get(), index)); }); FenceInstClass .def("__repr__", - [](PyFenceInst &self) { + [](PymFenceInst &self) { return ""; }) .def_prop_rw("ordering", - [](PyFenceInst &self) { + [](PymFenceInst &self) { return LLVMGetOrdering(self.get()); }, - [](PyFenceInst &self, LLVMAtomicOrdering ordering) { + [](PymFenceInst &self, LLVMAtomicOrdering ordering) { return LLVMSetOrdering(self.get(), ordering); }) .def_prop_rw("is_single_thread", - [](PyFenceInst &self) { + [](PymFenceInst &self) { return LLVMIsAtomicSingleThread(self.get()) != 0; }, - [](PyFenceInst &self, bool isSingleThread) { + [](PymFenceInst &self, bool isSingleThread) { return LLVMSetAtomicSingleThread(self.get(), isSingleThread); }); LoadInstClass .def("__repr__", - [](PyLoadInst &self) { + [](PymLoadInst &self) { return ""; }) .def_prop_rw("alignment", - [](PyLoadInst &v) { + [](PymLoadInst &v) { return LLVMGetAlignment(v.get()); }, - [](PyLoadInst &v, unsigned Bytes) { + [](PymLoadInst &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_rw("is_volatile", - [](PyLoadInst &self) { + [](PymLoadInst &self) { return LLVMGetVolatile(self.get()) != 0; }, - [](PyLoadInst &self, bool isVolatile) { + [](PymLoadInst &self, bool isVolatile) { return LLVMSetVolatile(self.get(), isVolatile); }) .def_prop_rw("ordering", - [](PyLoadInst &self) { + [](PymLoadInst &self) { return LLVMGetOrdering(self.get()); }, - [](PyLoadInst &self, LLVMAtomicOrdering ordering) { + [](PymLoadInst &self, LLVMAtomicOrdering ordering) { return LLVMSetOrdering(self.get(), ordering); }) .def_prop_rw("is_single_thread", - [](PyLoadInst &self) { + [](PymLoadInst &self) { return LLVMIsAtomicSingleThread(self.get()) != 0; }, - [](PyLoadInst &self, bool isSingleThread) { + [](PymLoadInst &self, bool isSingleThread) { return LLVMSetAtomicSingleThread(self.get(), isSingleThread); }); StoreInstClass .def("__repr__", - [](PyStoreInst &self) { + [](PymStoreInst &self) { return ""; }) .def_prop_rw("alignment", - [](PyStoreInst &v) { + [](PymStoreInst &v) { return LLVMGetAlignment(v.get()); }, - [](PyStoreInst &v, unsigned Bytes) { + [](PymStoreInst &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_rw("is_volatile", - [](PyStoreInst &self) { + [](PymStoreInst &self) { return LLVMGetVolatile(self.get()) != 0; }, - [](PyStoreInst &self, bool isVolatile) { + [](PymStoreInst &self, bool isVolatile) { return LLVMSetVolatile(self.get(), isVolatile); }) .def_prop_rw("ordering", - [](PyStoreInst &self) { + [](PymStoreInst &self) { return LLVMGetOrdering(self.get()); }, - [](PyStoreInst &self, LLVMAtomicOrdering ordering) { + [](PymStoreInst &self, LLVMAtomicOrdering ordering) { return LLVMSetOrdering(self.get(), ordering); }) .def_prop_rw("is_single_thread", - [](PyStoreInst &self) { + [](PymStoreInst &self) { return LLVMIsAtomicSingleThread(self.get()) != 0; }, - [](PyStoreInst &self, bool isSingleThread) { + [](PymStoreInst &self, bool isSingleThread) { return LLVMSetAtomicSingleThread(self.get(), isSingleThread); }); AtomicRMWInstClass .def("__repr__", - [](PyAtomicRMWInst &self) { + [](PymAtomicRMWInst &self) { return ""; }) .def_prop_rw("alignment", - [](PyAtomicRMWInst &v) { + [](PymAtomicRMWInst &v) { return LLVMGetAlignment(v.get()); }, - [](PyAtomicRMWInst &v, unsigned Bytes) { + [](PymAtomicRMWInst &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_rw("is_volatile", - [](PyAtomicRMWInst &self) { + [](PymAtomicRMWInst &self) { return LLVMGetVolatile(self.get()) != 0; }, - [](PyAtomicRMWInst &self, bool isVolatile) { + [](PymAtomicRMWInst &self, bool isVolatile) { return LLVMSetVolatile(self.get(), isVolatile); }) .def_prop_rw("ordering", - [](PyAtomicRMWInst &self) { + [](PymAtomicRMWInst &self) { return LLVMGetOrdering(self.get()); }, - [](PyAtomicRMWInst &self, LLVMAtomicOrdering ordering) { + [](PymAtomicRMWInst &self, LLVMAtomicOrdering ordering) { return LLVMSetOrdering(self.get(), ordering); }) .def_prop_rw("bin_op", - [](PyAtomicRMWInst &self) { + [](PymAtomicRMWInst &self) { return LLVMGetAtomicRMWBinOp(self.get()); }, - [](PyAtomicRMWInst &self, LLVMAtomicRMWBinOp binOp) { + [](PymAtomicRMWInst &self, LLVMAtomicRMWBinOp binOp) { return LLVMSetAtomicRMWBinOp(self.get(), binOp); }) .def_prop_rw("is_single_thread", - [](PyAtomicRMWInst &self) { + [](PymAtomicRMWInst &self) { return LLVMIsAtomicSingleThread(self.get()) != 0; }, - [](PyAtomicRMWInst &self, bool isSingleThread) { + [](PymAtomicRMWInst &self, bool isSingleThread) { return LLVMSetAtomicSingleThread(self.get(), isSingleThread); }); AtomicCmpXchgInstClass .def("__repr__", - [](PyAtomicCmpXchgInst &self) { + [](PymAtomicCmpXchgInst &self) { return ""; }) .def_prop_rw("alignment", - [](PyAtomicCmpXchgInst &v) { + [](PymAtomicCmpXchgInst &v) { return LLVMGetAlignment(v.get()); }, - [](PyAtomicCmpXchgInst &v, unsigned Bytes) { + [](PymAtomicCmpXchgInst &v, unsigned Bytes) { return LLVMSetAlignment(v.get(), Bytes); }, nb::for_setter (nb::sig("def alignment(self, bytes: int, /) -> None"))) .def_prop_rw("is_volatile", - [](PyLoadInst &self) { + [](PymLoadInst &self) { return LLVMGetVolatile(self.get()) != 0; }, - [](PyLoadInst &self, bool isVolatile) { + [](PymLoadInst &self, bool isVolatile) { return LLVMSetVolatile(self.get(), isVolatile); }) .def_prop_rw("is_weak", - [](PyAtomicCmpXchgInst &self) { + [](PymAtomicCmpXchgInst &self) { return LLVMGetWeak(self.get()); }, - [](PyAtomicCmpXchgInst &self, bool isWeak) { + [](PymAtomicCmpXchgInst &self, bool isWeak) { return LLVMSetWeak(self.get(), isWeak); }) .def_prop_rw("is_single_thread", - [](PyAtomicCmpXchgInst &self) { + [](PymAtomicCmpXchgInst &self) { return LLVMIsAtomicSingleThread(self.get()) != 0; }, - [](PyAtomicCmpXchgInst &self, bool isSingleThread) { + [](PymAtomicCmpXchgInst &self, bool isSingleThread) { return LLVMSetAtomicSingleThread(self.get(), isSingleThread); }) .def_prop_rw("success_ordering", - [](PyAtomicCmpXchgInst &self) { + [](PymAtomicCmpXchgInst &self) { return LLVMGetCmpXchgSuccessOrdering(self.get()); }, - [](PyAtomicCmpXchgInst &self, LLVMAtomicOrdering ordering) { + [](PymAtomicCmpXchgInst &self, LLVMAtomicOrdering ordering) { return LLVMSetCmpXchgSuccessOrdering(self.get(), ordering); }) .def_prop_rw("failure_ordering", - [](PyAtomicCmpXchgInst &self) { + [](PymAtomicCmpXchgInst &self) { return LLVMGetCmpXchgFailureOrdering(self.get()); }, - [](PyAtomicCmpXchgInst &self, LLVMAtomicOrdering ordering) { + [](PymAtomicCmpXchgInst &self, LLVMAtomicOrdering ordering) { return LLVMSetCmpXchgFailureOrdering(self.get(), ordering); }); GlobalObjectClass .def("__repr__", - [](PyGlobalObject &self) { + [](PymGlobalObject &self) { return gen_value_repr("GlobalObject", self); }) .def("set_metadata", - [](PyGlobalObject &g, unsigned kind, PyMetadata md) { + [](PymGlobalObject &g, unsigned kind, PymMetadata md) { return LLVMGlobalSetMetadata(g.get(), kind, md.get()); }, "Sets a metadata attachment, erasing the existing metadata attachment if" "it already exists for the given kind.") .def("erase_metadata", - [](PyGlobalObject &g, unsigned kind) { + [](PymGlobalObject &g, unsigned kind) { return LLVMGlobalEraseMetadata(g.get(), kind); }, "Erases a metadata attachment of the given kind if it exists.") .def("clear_metadata", - [](PyGlobalObject &g) { + [](PymGlobalObject &g) { return LLVMGlobalClearMetadata(g.get()); }, "Removes all metadata attachments from this value.") .def("copy_all_metadata", - [](PyGlobalObject &g) { + [](PymGlobalObject &g) { size_t num; LLVMValueMetadataEntries entries = LLVMGlobalCopyAllMetadata (g.get(), &num); - return PyMetadataEntries(entries, num); + return PymMetadataEntries(entries, num); }, "Retrieves an array of metadata entries representing the metadata attached to" "this value."); IndirectBrInstClass .def("__repr__", - [](PyIndirectBrInst &self) { + [](PymIndirectBrInst &self) { return ""; }) .def("add_destination", - [](PyIndirectBrInst &self, PyBasicBlock &dest) { + [](PymIndirectBrInst &self, PymBasicBlock &dest) { return LLVMAddDestination(self.get(), dest.get()); }, "dest"_a, @@ -2016,27 +2016,27 @@ void bindValueClasses(nb::module_ &m) { LandingPadInstClass .def("__repr__", - [](PyLandingPadInst &self) { + [](PymLandingPadInst &self) { return ""; }) .def_prop_ro("num_clauses", - [](PyIndirectBrInst &self) { + [](PymIndirectBrInst &self) { return LLVMGetNumClauses(self.get()); }) .def_prop_rw("is_cleanup", - [](PyLandingPadInst &self) { + [](PymLandingPadInst &self) { return LLVMIsCleanup(self.get()) != 0; }, - [](PyLandingPadInst &self, bool val) { + [](PymLandingPadInst &self, bool val) { return LLVMSetCleanup(self.get(), val); }) .def("get_clause", - [](PyIndirectBrInst &self, unsigned index) { - return PyValueAuto(LLVMGetClause(self.get(), index)); + [](PymIndirectBrInst &self, unsigned index) { + return PymValueAuto(LLVMGetClause(self.get(), index)); }, "index"_a) .def("add_clause", - [](PyIndirectBrInst &self, PyConstant clause) { + [](PymIndirectBrInst &self, PymConstant clause) { return LLVMAddClause(self.get(), clause.get()); }); diff --git a/src/llvm/Core/value.h b/src/llvm/Core/value.h index d92f0e0..b07bd6c 100644 --- a/src/llvm/Core/value.h +++ b/src/llvm/Core/value.h @@ -6,22 +6,22 @@ #define PY_DECLARE_VALUE_CAST(name) \ .def("to_" #name, \ - [](PyValue &v) -> std::optional { \ + [](PymValue &v) -> std::optional { \ auto res = LLVMIsA##name(v.get()); \ if (res) \ - return PyValueAuto(res); \ + return PymValueAuto(res); \ return std::nullopt; \ }, \ "Origin function: LLVMIsA" #name "\n\n" \ "None means conversion failed.\n\n" \ "Note if the target class is not supported in python binding, then it will " \ - "return a generic PyValue type object") + "return a generic PymValue type object") #define CONSTANT_EXPR_BIND_BINARY_OP(NAME, FUNCTION) \ .def_static(#NAME, \ - [](PyConstant &lhs, PyConstant &rhs) { \ - return PyValueAuto(FUNCTION(lhs.get(), rhs.get())); \ + [](PymConstant &lhs, PymConstant &rhs) { \ + return PymValueAuto(FUNCTION(lhs.get(), rhs.get())); \ }, \ "lhs"_a, "rhs"_a) diff --git a/src/llvm/TargetMachine.cpp b/src/llvm/TargetMachine.cpp index 5940302..24fdd36 100644 --- a/src/llvm/TargetMachine.cpp +++ b/src/llvm/TargetMachine.cpp @@ -13,19 +13,19 @@ namespace nb = nanobind; using namespace nb::literals; void populateTargetMachine(nanobind::module_ &m) { - BIND_ITERATOR_CLASS(PyTargetIterator, "TargetIterator") + BIND_ITERATOR_CLASS(PymTargetIterator, "TargetIterator") auto TargetMachineClass = - nb::class_> + nb::class_> (m, "TargetMachine", "TargetMachine"); auto TargetMachineOptionsClass = - nb::class_> + nb::class_> (m, "TargetMachineOptions", "TargetMachineOptions"); auto TargetClass = - nb::class_>(m, "Target", "Target"); + nb::class_>(m, "Target", "Target"); nb::enum_(m, "CodeGenOptLevel", "CodeGenOptLevel") @@ -55,15 +55,15 @@ void populateTargetMachine(nanobind::module_ &m) { .value("Large", LLVMCodeModel::LLVMCodeModelLarge); TargetClass - .def("__iter__", [](PyTarget &self) { return PyTargetIterator(self); }) + .def("__iter__", [](PymTarget &self) { return PymTargetIterator(self); }) .def_static("get_first", []() { - return PyTarget(LLVMGetFirstTarget()); + return PymTarget(LLVMGetFirstTarget()); }, "Returns the first llvm::Target in the registered targets list.") .def_static("get_from_name", [](const char *name) { - return PyTarget(LLVMGetTargetFromName(name)); + return PymTarget(LLVMGetTargetFromName(name)); }, "name"_a, "Finds the target corresponding to the given name") @@ -72,114 +72,114 @@ void populateTargetMachine(nanobind::module_ &m) { char *errorMessage; LLVMTargetRef T; auto res = LLVMGetTargetFromTriple(triple, &T, &errorMessage) == 0; - WRAP_DISPOSE_MESSAGE_RUNTIME_ERROR(res, errorMessage, PyTarget); + WRAP_DISPOSE_MESSAGE_RUNTIME_ERROR(res, errorMessage, PymTarget); }, "triple"_a, "Finds the target corresponding to the given triple." "Raises:\n" "\tRuntimeError") .def_prop_ro("name", - [](PyTarget &self) { + [](PymTarget &self) { return LLVMGetTargetName(self.get()); }) .def_prop_ro("description", - [](PyTarget &self) { + [](PymTarget &self) { return LLVMGetTargetDescription(self.get()); }) .def_prop_ro("has_jit", - [](PyTarget &self) { + [](PymTarget &self) { return LLVMTargetHasJIT(self.get()) != 0; }) .def_prop_ro("has_target_machine", - [](PyTarget &self) { + [](PymTarget &self) { return LLVMTargetHasTargetMachine(self.get()) != 0; }) .def_prop_ro("has_asm_backend", - [](PyTarget &self) { + [](PymTarget &self) { return LLVMTargetHasTargetMachine(self.get()) != 0; }) .def_prop_ro("next", - [](PyTarget &self) -> std::optional { + [](PymTarget &self) -> std::optional { auto res = LLVMGetNextTarget(self.get()); - WRAP_OPTIONAL_RETURN(res, PyTarget); + WRAP_OPTIONAL_RETURN(res, PymTarget); }, "Returns the next llvm::Target given a previous one (or null " "if there's none)"); TargetMachineOptionsClass .def("__init__", - [](PyTargetMachineOptions *tmo) { - new (tmo) PyTargetMachineOptions(LLVMCreateTargetMachineOptions()); + [](PymTargetMachineOptions *tmo) { + new (tmo) PymTargetMachineOptions(LLVMCreateTargetMachineOptions()); }) .def("set_cpu", - [](PyTargetMachineOptions &self, const char *cpu) { + [](PymTargetMachineOptions &self, const char *cpu) { return LLVMTargetMachineOptionsSetCPU(self.get(), cpu); }, "cpu"_a) .def("set_features", - [](PyTargetMachineOptions &self, const char *features) { + [](PymTargetMachineOptions &self, const char *features) { return LLVMTargetMachineOptionsSetFeatures(self.get(), features); }, "features"_a) .def("set_abi", - [](PyTargetMachineOptions &self, const char *abi) { + [](PymTargetMachineOptions &self, const char *abi) { return LLVMTargetMachineOptionsSetABI(self.get(), abi); }, "abi"_a) .def("set_code_gen_opt_level", - [](PyTargetMachineOptions &self, LLVMCodeGenOptLevel level) { + [](PymTargetMachineOptions &self, LLVMCodeGenOptLevel level) { return LLVMTargetMachineOptionsSetCodeGenOptLevel(self.get(), level); }, "level"_a) .def("set_reloc_mode", - [](PyTargetMachineOptions &self, LLVMRelocMode reloc) { + [](PymTargetMachineOptions &self, LLVMRelocMode reloc) { return LLVMTargetMachineOptionsSetRelocMode(self.get(), reloc); }, "reloc"_a) .def("set_code_model", - [](PyTargetMachineOptions &self, LLVMCodeModel codeModel) { + [](PymTargetMachineOptions &self, LLVMCodeModel codeModel) { return LLVMTargetMachineOptionsSetCodeModel(self.get(), codeModel); }, "code_model"_a); TargetMachineClass .def("__init__", - [](PyTargetMachine *tm, PyTarget &T, const char *triple, - PyTargetMachineOptions options) { + [](PymTargetMachine *tm, PymTarget &T, const char *triple, + PymTargetMachineOptions options) { auto res = LLVMCreateTargetMachineWithOptions (T.get(), triple, options.get()); - new (tm) PyTargetMachine(res); + new (tm) PymTargetMachine(res); }, "target"_a, "triple"_a, "options"_a) .def("__init__", - [](PyTargetMachine *tm, PyTarget &T, const char *triple, const char *cpu, + [](PymTargetMachine *tm, PymTarget &T, const char *triple, const char *cpu, const char *features, LLVMCodeGenOptLevel level, LLVMRelocMode reloc, LLVMCodeModel codeModel) { auto res = LLVMCreateTargetMachine (T.get(), triple, cpu, features, level, reloc, codeModel); - new (tm) PyTargetMachine(res); + new (tm) PymTargetMachine(res); }) .def_prop_ro("target", - [](PyTargetMachine &self) { - return PyTarget(LLVMGetTargetMachineTarget(self.get())); + [](PymTargetMachine &self) { + return PymTarget(LLVMGetTargetMachineTarget(self.get())); }) .def_prop_ro("triple", - [](PyTargetMachine &self) { + [](PymTargetMachine &self) { auto res = LLVMGetTargetMachineTriple(self.get()); RETURN_MESSAGE(res); }) .def_prop_ro("cpu", - [](PyTargetMachine &self) { + [](PymTargetMachine &self) { auto res = LLVMGetTargetMachineCPU(self.get()); RETURN_MESSAGE(res); }) .def_prop_ro("feature_string", - [](PyTargetMachine &self) { + [](PymTargetMachine &self) { auto res = LLVMGetTargetMachineFeatureString(self.get()); RETURN_MESSAGE(res); }); // TODO nedd // .def_prop_ro("data_layout", - // [](PyTargetMachine &self) { + // [](PymTargetMachine &self) { // return LLVMCreateTargetDataLayout(self.get()); // }); } diff --git a/src/llvm/Utils.cpp b/src/llvm/Utils.cpp index a8db5c2..e223e12 100644 --- a/src/llvm/Utils.cpp +++ b/src/llvm/Utils.cpp @@ -8,8 +8,8 @@ namespace nb = nanobind; using namespace nb::literals; -PyModule parseAssembly(std::string &iasm) { - auto context = PyContext::getGlobalContext(); +PymModule parseAssembly(std::string &iasm) { + auto context = PymContext::getGlobalContext(); auto memBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(iasm.c_str(), iasm.size(), ""); return parseIR(context.get(), memBuf); } diff --git a/src/llvm/types_priv.h b/src/llvm/types_priv.h index ba390c4..7e78d2b 100644 --- a/src/llvm/types_priv.h +++ b/src/llvm/types_priv.h @@ -14,22 +14,22 @@ #include #include -#include "types_priv/PyModule.h" -#include "types_priv/PyContext.h" -#include "types_priv/PyMetadataEntries.h" -#include "types_priv/PyModuleFlagEntries.h" -#include "types_priv/PyOperandBundle.h" -#include "types_priv/PyPassManagerBase.h" -#include "types_priv/PyMemoryBuffer.h" -#include "types_priv/PyModuleProvider.h" -#include "types_priv/PyTargetData.h" -#include "types_priv/PyTargetMachine.h" -#include "types_priv/PyTargetMachineOptions.h" -#include "types_priv/PyLLVMObject.h" +#include "types_priv/PymModule.h" +#include "types_priv/PymContext.h" +#include "types_priv/PymMetadataEntries.h" +#include "types_priv/PymModuleFlagEntries.h" +#include "types_priv/PymOperandBundle.h" +#include "types_priv/PymPassManagerBase.h" +#include "types_priv/PymMemoryBuffer.h" +#include "types_priv/PymModuleProvider.h" +#include "types_priv/PymTargetData.h" +#include "types_priv/PymTargetMachine.h" +#include "types_priv/PymTargetMachineOptions.h" +#include "types_priv/PymLLVMObject.h" #define DEFINE_PY_WRAPPER_CLASS(ClassName, UnderlyingType) \ - class ClassName: public PyLLVMObject { \ + class ClassName: public PymLLVMObject { \ public: \ explicit ClassName(UnderlyingType raw) \ : raw(raw) {} \ @@ -43,7 +43,7 @@ }; #define DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(ClassName, UnderlyingType) \ - class ClassName: public PyLLVMObject { \ + class ClassName: public PymLLVMObject { \ public: \ virtual ~ClassName() = default; \ explicit ClassName(UnderlyingType raw) \ @@ -162,95 +162,95 @@ // e.g. // CallBase => CallInst & InvokeInst (refers to LLVM implementation code) // NOTE -// rename python side name of PyBasicBlock to BasicBlockValue to avoid collision -// with PyBasicBlockWrapper +// rename python side name of PymBasicBlock to BasicBlockValue to avoid collision +// with PymBasicBlockWrapper #define PY_FOR_EACH_VALUE_CLASS_RELATIONSHIP(macro) \ - macro(PyValue, PyMetadataAsValue) \ - macro(PyMetadataAsValue, PyMDNodeValue) \ - macro(PyMetadataAsValue, PyValueAsMetadataValue) \ - macro(PyMetadataAsValue, PyMDStringValue) \ - macro(PyValue, PyArgument) \ - macro(PyValue, PyBasicBlockValue) \ - macro(PyValue, PyInlineAsm) \ - macro(PyValue, PyUser) \ - macro(PyUser, PyConstant) \ - macro(PyConstant, PyConstantArray) \ - macro(PyConstant, PyConstantDataSequential) \ - macro(PyConstantDataSequential, PyConstantDataArray) \ - macro(PyConstantDataSequential, PyConstantDataVector) \ - macro(PyConstant, PyConstantExpr) \ - macro(PyConstant, PyConstantFP) \ - macro(PyConstant, PyConstantInt) \ - macro(PyConstant, PyConstantStruct) \ - macro(PyConstant, PyConstantVector) \ - macro(PyConstant, PyGlobalValue) \ - macro(PyGlobalValue, PyGlobalAlias) \ - macro(PyGlobalValue, PyGlobalObject) \ - macro(PyGlobalObject, PyFunction) \ - macro(PyGlobalObject, PyGlobalVariable) \ - macro(PyGlobalObject, PyGlobalIFunc) \ - macro(PyConstant, PyUndefValue) \ - macro(PyConstant, PyPoisonValue) \ - macro(PyUser, PyInstruction) \ - macro(PyInstruction, PyCallBase) \ - macro(PyCallBase, PyCallInst) \ - macro(PyCallBase, PyInvokeInst) \ - macro(PyInstruction, PyFCmpInst) \ - macro(PyInstruction, PyICmpInst) \ - macro(PyInstruction, PyGetElementPtrInst) \ - macro(PyInstruction, PyPHINode) \ - macro(PyInstruction, PyShuffleVectorInst) \ - macro(PyInstruction, PyReturnInst) \ - macro(PyInstruction, PySwitchInst) \ - macro(PyInstruction, PyCatchSwitchInst) \ - macro(PyInstruction, PyCleanupReturnInst) \ - macro(PyInstruction, PyFuncletPadInst) \ - macro(PyFuncletPadInst, PyCatchPadInst) \ - macro(PyInstruction, PyAllocaInst) \ - macro(PyInstruction, PyIEValueInstBase) \ - macro(PyIEValueInstBase, PyInsertValueInst) \ - macro(PyIEValueInstBase, PyExtractValueInst) \ - macro(PyInstruction, PyBranchInst) \ - macro(PyInstruction, PyIndirectBrInst) \ - macro(PyInstruction, PyLandingPadInst) \ - macro(PyInstruction, PyLoadInst) \ - macro(PyInstruction, PyStoreInst) \ - macro(PyInstruction, PyAtomicRMWInst) \ - macro(PyInstruction, PyAtomicCmpXchgInst) \ - macro(PyInstruction, PyFenceInst) + macro(PymValue, PymMetadataAsValue) \ + macro(PymMetadataAsValue, PymMDNodeValue) \ + macro(PymMetadataAsValue, PymValueAsMetadataValue) \ + macro(PymMetadataAsValue, PymMDStringValue) \ + macro(PymValue, PymArgument) \ + macro(PymValue, PymBasicBlockValue) \ + macro(PymValue, PymInlineAsm) \ + macro(PymValue, PymUser) \ + macro(PymUser, PymConstant) \ + macro(PymConstant, PymConstantArray) \ + macro(PymConstant, PymConstantDataSequential) \ + macro(PymConstantDataSequential, PymConstantDataArray) \ + macro(PymConstantDataSequential, PymConstantDataVector) \ + macro(PymConstant, PymConstantExpr) \ + macro(PymConstant, PymConstantFP) \ + macro(PymConstant, PymConstantInt) \ + macro(PymConstant, PymConstantStruct) \ + macro(PymConstant, PymConstantVector) \ + macro(PymConstant, PymGlobalValue) \ + macro(PymGlobalValue, PymGlobalAlias) \ + macro(PymGlobalValue, PymGlobalObject) \ + macro(PymGlobalObject, PymFunction) \ + macro(PymGlobalObject, PymGlobalVariable) \ + macro(PymGlobalObject, PymGlobalIFunc) \ + macro(PymConstant, PymUndefValue) \ + macro(PymConstant, PymPoisonValue) \ + macro(PymUser, PymInstruction) \ + macro(PymInstruction, PymCallBase) \ + macro(PymCallBase, PymCallInst) \ + macro(PymCallBase, PymInvokeInst) \ + macro(PymInstruction, PymFCmpInst) \ + macro(PymInstruction, PymICmpInst) \ + macro(PymInstruction, PymGetElementPtrInst) \ + macro(PymInstruction, PymPHINode) \ + macro(PymInstruction, PymShuffleVectorInst) \ + macro(PymInstruction, PymReturnInst) \ + macro(PymInstruction, PymSwitchInst) \ + macro(PymInstruction, PymCatchSwitchInst) \ + macro(PymInstruction, PymCleanupReturnInst) \ + macro(PymInstruction, PymFuncletPadInst) \ + macro(PymFuncletPadInst, PymCatchPadInst) \ + macro(PymInstruction, PymAllocaInst) \ + macro(PymInstruction, PymIEValueInstBase) \ + macro(PymIEValueInstBase, PymInsertValueInst) \ + macro(PymIEValueInstBase, PymExtractValueInst) \ + macro(PymInstruction, PymBranchInst) \ + macro(PymInstruction, PymIndirectBrInst) \ + macro(PymInstruction, PymLandingPadInst) \ + macro(PymInstruction, PymLoadInst) \ + macro(PymInstruction, PymStoreInst) \ + macro(PymInstruction, PymAtomicRMWInst) \ + macro(PymInstruction, PymAtomicCmpXchgInst) \ + macro(PymInstruction, PymFenceInst) #define PY_FOR_EACH_TYPE_CLASS_RELASIONSHIP(macro) \ - macro(PyType, PyTypeInt) \ - macro(PyType, PyTypeReal) \ - macro(PyType, PyTypeFunction) \ - macro(PyType, PyTypeStruct) \ - macro(PyType, PyTypeSequence) \ - macro(PyTypeSequence, PyTypeArray) \ - macro(PyTypeSequence, PyTypePointer) \ - macro(PyTypeSequence, PyTypeVector) \ - macro(PyType, PyTypeVoid) \ - macro(PyType, PyTypeLabel) \ - macro(PyType, PyTypeX86MMX) \ - macro(PyType, PyTypeX86AMX) \ - macro(PyType, PyTypeToken) \ - macro(PyType, PyTypeMetadata) \ - macro(PyType, PyTypeTargetExt) - - -#define BIND_PYLLVMOBJECT_(ClassName, UnderlyingType, PyClassName) \ - nb::class_> \ - (m, #PyClassName, "The base class.") \ - .def("__bool__", &PyLLVMObject::__bool__) \ - .def("__eq__", &PyLLVMObject::__equal__) \ - .def("__hash__", &PyLLVMObject::__hash__); - - -enum class PyAttributeIndex { + macro(PymType, PymTypeInt) \ + macro(PymType, PymTypeReal) \ + macro(PymType, PymTypeFunction) \ + macro(PymType, PymTypeStruct) \ + macro(PymType, PymTypeSequence) \ + macro(PymTypeSequence, PymTypeArray) \ + macro(PymTypeSequence, PymTypePointer) \ + macro(PymTypeSequence, PymTypeVector) \ + macro(PymType, PymTypeVoid) \ + macro(PymType, PymTypeLabel) \ + macro(PymType, PymTypeX86MMX) \ + macro(PymType, PymTypeX86AMX) \ + macro(PymType, PymTypeToken) \ + macro(PymType, PymTypeMetadata) \ + macro(PymType, PymTypeTargetExt) + + +#define BIND_PYLLVMOBJECT_(ClassName, UnderlyingType, PymClassName) \ + nb::class_> \ + (m, #PymClassName, "The base class.") \ + .def("__bool__", &PymLLVMObject::__bool__) \ + .def("__eq__", &PymLLVMObject::__equal__) \ + .def("__hash__", &PymLLVMObject::__hash__); + + +enum class PymAttributeIndex { Return = LLVMAttributeReturnIndex, Function = LLVMAttributeFunctionIndex }; -enum class PyLLVMFastMathFlags { +enum class PymLLVMFastMathFlags { AllowReassoc = LLVMFastMathAllowReassoc, NoNaNs = LLVMFastMathNoNaNs, NoInfs = LLVMFastMathNoInfs, @@ -264,70 +264,70 @@ enum class PyLLVMFastMathFlags { /* * Check three places: here, class inheritance, binding class inheritance - * NOTE the `__bool__` method of PyIntrinsic is overridden + * NOTE the `__bool__` method of PymIntrinsic is overridden */ #define BIND_PYLLVMOBJECT() \ - BIND_PYLLVMOBJECT_(PyValue, LLVMValueRef, PyValueObject) \ - BIND_PYLLVMOBJECT_(PyType, LLVMTypeRef, PyTypeObject) \ - BIND_PYLLVMOBJECT_(PyDiagnosticInfo, LLVMDiagnosticInfoRef, PyDiagnosticInfoObject) \ - BIND_PYLLVMOBJECT_(PyAttribute, LLVMAttributeRef, PyAttributeObject) \ - BIND_PYLLVMOBJECT_(PyNamedMDNode, LLVMNamedMDNodeRef, PyNamedMDNodeObject) \ - BIND_PYLLVMOBJECT_(PyUse, LLVMUseRef, PyUseObject) \ - BIND_PYLLVMOBJECT_(PyBasicBlock, LLVMBasicBlockRef, PyBasicBlockObject) \ - BIND_PYLLVMOBJECT_(PyBuilder, LLVMBuilderRef, PyBuilderObject) \ - BIND_PYLLVMOBJECT_(PyMetadata, LLVMMetadataRef, PyMetadataObject) \ - BIND_PYLLVMOBJECT_(PyIntrinsic, unsigned, PyIntrinsicObject) \ + BIND_PYLLVMOBJECT_(PymValue, LLVMValueRef, PymValueObject) \ + BIND_PYLLVMOBJECT_(PymType, LLVMTypeRef, PymTypeObject) \ + BIND_PYLLVMOBJECT_(PymDiagnosticInfo, LLVMDiagnosticInfoRef, PymDiagnosticInfoObject) \ + BIND_PYLLVMOBJECT_(PymAttribute, LLVMAttributeRef, PymAttributeObject) \ + BIND_PYLLVMOBJECT_(PymNamedMDNode, LLVMNamedMDNodeRef, PymNamedMDNodeObject) \ + BIND_PYLLVMOBJECT_(PymUse, LLVMUseRef, PymUseObject) \ + BIND_PYLLVMOBJECT_(PymBasicBlock, LLVMBasicBlockRef, PymBasicBlockObject) \ + BIND_PYLLVMOBJECT_(PymBuilder, LLVMBuilderRef, PymBuilderObject) \ + BIND_PYLLVMOBJECT_(PymMetadata, LLVMMetadataRef, PymMetadataObject) \ + BIND_PYLLVMOBJECT_(PymIntrinsic, unsigned, PymIntrinsicObject) \ \ - BIND_PYLLVMOBJECT_(PyContext, LLVMContextRef, PyContextObject) \ - BIND_PYLLVMOBJECT_(PyMemoryBuffer, LLVMMemoryBufferRef, PyMemoryBufferObject) \ - BIND_PYLLVMOBJECT_(PyMetadataEntries, LLVMValueMetadataEntries, PyMetadataEntriesObject) \ - BIND_PYLLVMOBJECT_(PyModuleFlagEntries, LLVMModuleFlagEntries, PyModuleFlagEntriesObject) \ - BIND_PYLLVMOBJECT_(PyModule, LLVMModuleRef, PyModuleObject) \ - BIND_PYLLVMOBJECT_(PyModuleProvider, LLVMModuleProviderRef, PyModuleProviderObject) \ - BIND_PYLLVMOBJECT_(PyOperandBundle, LLVMOperandBundleRef, PyOperandBundleObject) \ - BIND_PYLLVMOBJECT_(PyPassManagerBase, LLVMPassManagerRef, PyPassManagerBaseObject) \ + BIND_PYLLVMOBJECT_(PymContext, LLVMContextRef, PymContextObject) \ + BIND_PYLLVMOBJECT_(PymMemoryBuffer, LLVMMemoryBufferRef, PymMemoryBufferObject) \ + BIND_PYLLVMOBJECT_(PymMetadataEntries, LLVMValueMetadataEntries, PymMetadataEntriesObject) \ + BIND_PYLLVMOBJECT_(PymModuleFlagEntries, LLVMModuleFlagEntries, PymModuleFlagEntriesObject) \ + BIND_PYLLVMOBJECT_(PymModule, LLVMModuleRef, PymModuleObject) \ + BIND_PYLLVMOBJECT_(PymModuleProvider, LLVMModuleProviderRef, PymModuleProviderObject) \ + BIND_PYLLVMOBJECT_(PymOperandBundle, LLVMOperandBundleRef, PymOperandBundleObject) \ + BIND_PYLLVMOBJECT_(PymPassManagerBase, LLVMPassManagerRef, PymPassManagerBaseObject) \ \ - BIND_PYLLVMOBJECT_(PyTarget, LLVMTargetRef, PyTargetObject) \ - BIND_PYLLVMOBJECT_(PyTargetMachine, LLVMTargetMachineRef, PyTargetMachineObject) \ - BIND_PYLLVMOBJECT_(PyTargetMachineOptions, LLVMTargetMachineOptionsRef, \ - PyTargetMachineOptionsObject) \ + BIND_PYLLVMOBJECT_(PymTarget, LLVMTargetRef, PymTargetObject) \ + BIND_PYLLVMOBJECT_(PymTargetMachine, LLVMTargetMachineRef, PymTargetMachineObject) \ + BIND_PYLLVMOBJECT_(PymTargetMachineOptions, LLVMTargetMachineOptionsRef, \ + PymTargetMachineOptionsObject) \ \ - BIND_PYLLVMOBJECT_(PyTargetData, LLVMTargetDataRef, PyTargetDataObject) + BIND_PYLLVMOBJECT_(PymTargetData, LLVMTargetDataRef, PymTargetDataObject) // Core -------------------------------------------------------- -DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PyValue, LLVMValueRef) -DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PyType, LLVMTypeRef) -DEFINE_PY_WRAPPER_CLASS(PyDiagnosticInfo, LLVMDiagnosticInfoRef) -DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PyAttribute, LLVMAttributeRef) -DEFINE_PY_WRAPPER_CLASS(PyNamedMDNode, LLVMNamedMDNodeRef) -DEFINE_PY_WRAPPER_CLASS(PyUse, LLVMUseRef) -DEFINE_PY_WRAPPER_CLASS(PyBasicBlock, LLVMBasicBlockRef) -DEFINE_PY_WRAPPER_CLASS(PyBuilder, LLVMBuilderRef) +DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PymValue, LLVMValueRef) +DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PymType, LLVMTypeRef) +DEFINE_PY_WRAPPER_CLASS(PymDiagnosticInfo, LLVMDiagnosticInfoRef) +DEFINE_PY_WRAPPER_CLASS_POLYMORPHIC(PymAttribute, LLVMAttributeRef) +DEFINE_PY_WRAPPER_CLASS(PymNamedMDNode, LLVMNamedMDNodeRef) +DEFINE_PY_WRAPPER_CLASS(PymUse, LLVMUseRef) +DEFINE_PY_WRAPPER_CLASS(PymBasicBlock, LLVMBasicBlockRef) +DEFINE_PY_WRAPPER_CLASS(PymBuilder, LLVMBuilderRef) -DEFINE_PY_WRAPPER_CLASS(PyMetadata, LLVMMetadataRef) +DEFINE_PY_WRAPPER_CLASS(PymMetadata, LLVMMetadataRef) -DEFINE_DIRECT_SUB_CLASS(PyMetadata, PyMDNode) -DEFINE_DIRECT_SUB_CLASS(PyMetadata, PyValueAsMetadata) -DEFINE_DIRECT_SUB_CLASS(PyMetadata, PyMDString) +DEFINE_DIRECT_SUB_CLASS(PymMetadata, PymMDNode) +DEFINE_DIRECT_SUB_CLASS(PymMetadata, PymValueAsMetadata) +DEFINE_DIRECT_SUB_CLASS(PymMetadata, PymMDString) -DEFINE_DIRECT_SUB_CLASS(PyAttribute, PyEnumAttribute); -DEFINE_DIRECT_SUB_CLASS(PyAttribute, PyTypeAttribute); -DEFINE_DIRECT_SUB_CLASS(PyAttribute, PyStringAttribute); +DEFINE_DIRECT_SUB_CLASS(PymAttribute, PymEnumAttribute); +DEFINE_DIRECT_SUB_CLASS(PymAttribute, PymTypeAttribute); +DEFINE_DIRECT_SUB_CLASS(PymAttribute, PymStringAttribute); PY_FOR_EACH_VALUE_CLASS_RELATIONSHIP(DEFINE_DIRECT_SUB_CLASS) PY_FOR_EACH_TYPE_CLASS_RELASIONSHIP(DEFINE_DIRECT_SUB_CLASS) -DEFINE_PY_WRAPPER_CLASS(PyIntrinsic, unsigned) +DEFINE_PY_WRAPPER_CLASS(PymIntrinsic, unsigned) -DEFINE_DIRECT_SUB_CLASS(PyPassManagerBase, PyPassManager); -DEFINE_DIRECT_SUB_CLASS(PyPassManagerBase, PyFunctionPassManager); +DEFINE_DIRECT_SUB_CLASS(PymPassManagerBase, PymPassManager); +DEFINE_DIRECT_SUB_CLASS(PymPassManagerBase, PymFunctionPassManager); #define DEFINE_ITERATOR_CLASS(TypeName, UnderlyingType, GetNextFn) \ @@ -351,8 +351,8 @@ DEFINE_DIRECT_SUB_CLASS(PyPassManagerBase, PyFunctionPassManager); UnderlyingType val; \ }; -#define BIND_ITERATOR_CLASS(ClassName, PythonClassName) \ - nanobind::class_(m, PythonClassName, PythonClassName) \ +#define BIND_ITERATOR_CLASS(ClassName, PymthonClassName) \ + nanobind::class_(m, PymthonClassName, PymthonClassName) \ .def("__iter__", [](ClassName &self) { return self; }) \ .def("__next__", &ClassName::next); @@ -360,22 +360,22 @@ DEFINE_DIRECT_SUB_CLASS(PyPassManagerBase, PyFunctionPassManager); -DEFINE_ITERATOR_CLASS(PyUseIterator, PyUse, LLVMGetNextUse) -// DEFINE_ITERATOR_CLASS(PyBasicBlockIterator, PyBasicBlock, LLVMGetNextBasicBlock) -// DEFINE_ITERATOR_CLASS(PyArgumentIterator, PyArgument, LLVMGetNextParam) -DEFINE_ITERATOR_CLASS(PyInstructionIterator, PyInstruction, LLVMGetNextInstruction) -DEFINE_ITERATOR_CLASS(PyGlobalVariableIterator, PyGlobalVariable, LLVMGetNextGlobal) -DEFINE_ITERATOR_CLASS(PyGlobalIFuncIterator, PyGlobalIFunc, LLVMGetNextGlobalIFunc) -DEFINE_ITERATOR_CLASS(PyGlobalAliasIterator, PyGlobalAlias, LLVMGetNextGlobalAlias) -DEFINE_ITERATOR_CLASS(PyNamedMDNodeIterator, PyNamedMDNode, LLVMGetNextNamedMetadata) -DEFINE_ITERATOR_CLASS(PyFunctionIterator, PyFunction, LLVMGetNextFunction) +DEFINE_ITERATOR_CLASS(PymUseIterator, PymUse, LLVMGetNextUse) +// DEFINE_ITERATOR_CLASS(PymBasicBlockIterator, PymBasicBlock, LLVMGetNextBasicBlock) +// DEFINE_ITERATOR_CLASS(PymArgumentIterator, PymArgument, LLVMGetNextParam) +DEFINE_ITERATOR_CLASS(PymInstructionIterator, PymInstruction, LLVMGetNextInstruction) +DEFINE_ITERATOR_CLASS(PymGlobalVariableIterator, PymGlobalVariable, LLVMGetNextGlobal) +DEFINE_ITERATOR_CLASS(PymGlobalIFuncIterator, PymGlobalIFunc, LLVMGetNextGlobalIFunc) +DEFINE_ITERATOR_CLASS(PymGlobalAliasIterator, PymGlobalAlias, LLVMGetNextGlobalAlias) +DEFINE_ITERATOR_CLASS(PymNamedMDNodeIterator, PymNamedMDNode, LLVMGetNextNamedMetadata) +DEFINE_ITERATOR_CLASS(PymFunctionIterator, PymFunction, LLVMGetNextFunction) // TargetMachine --------------------------------------------------------- -DEFINE_PY_WRAPPER_CLASS(PyTarget, LLVMTargetRef) -DEFINE_ITERATOR_CLASS(PyTargetIterator, PyTarget, LLVMGetNextTarget) +DEFINE_PY_WRAPPER_CLASS(PymTarget, LLVMTargetRef) +DEFINE_ITERATOR_CLASS(PymTargetIterator, PymTarget, LLVMGetNextTarget) diff --git a/src/llvm/types_priv/PyMemoryBuffer.cpp b/src/llvm/types_priv/PyMemoryBuffer.cpp deleted file mode 100644 index e8ae2db..0000000 --- a/src/llvm/types_priv/PyMemoryBuffer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "PyMemoryBuffer.h" -#include - -std::unordered_map> PyMemoryBuffer::obj_map; -std::mutex PyMemoryBuffer::map_mutex; - -PyMemoryBuffer::PyMemoryBuffer(LLVMMemoryBufferRef obj) : obj(get_shared_obj(obj)) { } - -LLVMMemoryBufferRef PyMemoryBuffer::get() const { - return obj.get(); -} - -// This function doesn't call `reset` method on shared_ptr object, since -// it will then call deleter, which is undesired and will lead to crash. -void PyMemoryBuffer::reset() { - LLVMMemoryBufferRef m = obj.get(); - if (m) { - std::lock_guard lock(PyMemoryBuffer::map_mutex); - PyMemoryBuffer::obj_map.erase(m); - } -} - - -void PyMemoryBuffer::Deleter::operator() -(LLVMMemoryBufferRef mb) const { - if (mb) { - std::lock_guard lock(PyMemoryBuffer::map_mutex); - auto it = PyMemoryBuffer::obj_map.find(mb); - - // the logic here is specially designed for `reset` function - if (it != PyMemoryBuffer::obj_map.end()) { - LLVMDisposeMemoryBuffer(mb); - - PyMemoryBuffer::obj_map.erase(mb); - } - } -} - - -std::shared_ptr PyMemoryBuffer::get_shared_obj -(LLVMMemoryBufferRef mb) { - std::lock_guard lock(PyMemoryBuffer::map_mutex); - auto it = PyMemoryBuffer::obj_map.find(mb); - - if (it != PyMemoryBuffer::obj_map.end()) { - if (auto shared = it->second.lock()) { - return shared; - } - } - - auto shared = std::shared_ptr(mb, Deleter()); - PyMemoryBuffer::obj_map[mb] = shared; - return shared; -} diff --git a/src/llvm/types_priv/PyMetadataEntries.cpp b/src/llvm/types_priv/PyMetadataEntries.cpp deleted file mode 100644 index b4b10e9..0000000 --- a/src/llvm/types_priv/PyMetadataEntries.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "PyMetadataEntries.h" - -PyMetadataEntries::PyMetadataEntries(LLVMValueMetadataEntries obj, size_t len) -: obj(get_shared_obj(obj)), len(len) { } - -LLVMValueMetadataEntries PyMetadataEntries::get() const { - return obj.get(); -} - -size_t PyMetadataEntries::getLen() const { - return len; -} - -SHARED_POINTER_IMPL(PyMetadataEntries, LLVMValueMetadataEntries, LLVMValueMetadataEntry, - LLVMDisposeValueMetadataEntries) - - diff --git a/src/llvm/types_priv/PyModuleFlagEntries.cpp b/src/llvm/types_priv/PyModuleFlagEntries.cpp deleted file mode 100644 index bc0898c..0000000 --- a/src/llvm/types_priv/PyModuleFlagEntries.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "PyModuleFlagEntries.h" - -PyModuleFlagEntries::PyModuleFlagEntries(LLVMModuleFlagEntries obj, size_t len) -: obj(get_shared_obj(obj)), len(len) { } - -LLVMModuleFlagEntries PyModuleFlagEntries::get() const { - return obj.get(); -} - -size_t PyModuleFlagEntries::getLen() const { - return len; -} - -SHARED_POINTER_IMPL(PyModuleFlagEntries, LLVMModuleFlagEntries, LLVMModuleFlagEntry, - LLVMDisposeModuleFlagsMetadata) diff --git a/src/llvm/types_priv/PyModuleProvider.cpp b/src/llvm/types_priv/PyModuleProvider.cpp deleted file mode 100644 index 7897a3d..0000000 --- a/src/llvm/types_priv/PyModuleProvider.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PyModuleProvider.h" - -PyModuleProvider::PyModuleProvider(LLVMModuleProviderRef obj) -: obj(get_shared_obj(obj)) {} - -LLVMModuleProviderRef PyModuleProvider::get() const { - return obj.get(); -} - -SHARED_POINTER_IMPL(PyModuleProvider, LLVMModuleProviderRef, LLVMOpaqueModuleProvider, - LLVMDisposeModuleProvider) diff --git a/src/llvm/types_priv/PyOperandBundle.cpp b/src/llvm/types_priv/PyOperandBundle.cpp deleted file mode 100644 index 7734bc0..0000000 --- a/src/llvm/types_priv/PyOperandBundle.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "PyOperandBundle.h" - -PyOperandBundle::PyOperandBundle(LLVMOperandBundleRef obj) -: obj(get_shared_obj(obj)) { } - -LLVMOperandBundleRef PyOperandBundle::get() const { - return obj.get(); -} - - -SHARED_POINTER_IMPL(PyOperandBundle, LLVMOperandBundleRef, LLVMOpaqueOperandBundle, - LLVMDisposeOperandBundle) - diff --git a/src/llvm/types_priv/PyPassManagerBase.cpp b/src/llvm/types_priv/PyPassManagerBase.cpp deleted file mode 100644 index 3ad2ab0..0000000 --- a/src/llvm/types_priv/PyPassManagerBase.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PyPassManagerBase.h" - -PyPassManagerBase::PyPassManagerBase(LLVMPassManagerRef obj) -: obj(get_shared_obj(obj)) { } - -LLVMPassManagerRef PyPassManagerBase::get() const { - return obj.get(); -} - -SHARED_POINTER_IMPL(PyPassManagerBase, LLVMPassManagerRef, LLVMOpaquePassManager, - LLVMDisposePassManager) diff --git a/src/llvm/types_priv/PyTargetData.cpp b/src/llvm/types_priv/PyTargetData.cpp deleted file mode 100644 index c39e915..0000000 --- a/src/llvm/types_priv/PyTargetData.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PyTargetData.h" - -PyTargetData::PyTargetData(LLVMTargetDataRef data) -: obj(get_shared_obj(data)) {} - -LLVMTargetDataRef PyTargetData::get() const { - return obj.get(); -} - -SHARED_POINTER_IMPL(PyTargetData, LLVMTargetDataRef, LLVMOpaqueTargetData, - LLVMDisposeTargetData) diff --git a/src/llvm/types_priv/PyTargetMachine.cpp b/src/llvm/types_priv/PyTargetMachine.cpp deleted file mode 100644 index 88798e4..0000000 --- a/src/llvm/types_priv/PyTargetMachine.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "PyTargetMachine.h" - -PyTargetMachine::PyTargetMachine(LLVMTargetMachineRef machine) -: obj(get_shared_obj(machine)) { } - -LLVMTargetMachineRef PyTargetMachine::get() const { - return obj.get(); -} - -SHARED_POINTER_IMPL(PyTargetMachine, LLVMTargetMachineRef, LLVMOpaqueTargetMachine, - LLVMDisposeTargetMachine) - diff --git a/src/llvm/types_priv/PyTargetMachineOptions.cpp b/src/llvm/types_priv/PyTargetMachineOptions.cpp deleted file mode 100644 index f6c0aec..0000000 --- a/src/llvm/types_priv/PyTargetMachineOptions.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "PyTargetMachineOptions.h" - -PyTargetMachineOptions::PyTargetMachineOptions(LLVMTargetMachineOptionsRef obj) -: obj(get_shared_obj(obj)) {} - -LLVMTargetMachineOptionsRef PyTargetMachineOptions::get() const { - return obj.get(); -} - - -SHARED_POINTER_IMPL(PyTargetMachineOptions, LLVMTargetMachineOptionsRef, - LLVMOpaqueTargetMachineOptions, LLVMDisposeTargetMachineOptions) diff --git a/src/llvm/types_priv/PyContext.cpp b/src/llvm/types_priv/PymContext.cpp similarity index 63% rename from src/llvm/types_priv/PyContext.cpp rename to src/llvm/types_priv/PymContext.cpp index 4359233..769e392 100644 --- a/src/llvm/types_priv/PyContext.cpp +++ b/src/llvm/types_priv/PymContext.cpp @@ -1,9 +1,9 @@ -#include "PyContext.h" +#include "PymContext.h" -std::unordered_map> PyContext::context_map; -std::mutex PyContext::map_mutex; +std::unordered_map> PymContext::context_map; +std::mutex PymContext::map_mutex; -PyContext::PyContext() { +PymContext::PymContext() { is_global_context = false; context = get_shared_context(LLVMContextCreate(), is_global_context); if (!context) { @@ -11,7 +11,7 @@ PyContext::PyContext() { } } -PyContext::PyContext(LLVMContextRef ctx, bool is_global_context) { +PymContext::PymContext(LLVMContextRef ctx, bool is_global_context) { is_global_context = is_global_context; context = get_shared_context(ctx, is_global_context); if (!context) { @@ -19,7 +19,7 @@ PyContext::PyContext(LLVMContextRef ctx, bool is_global_context) { } } -PyContext::PyContext(LLVMContextRef ctx) { +PymContext::PymContext(LLVMContextRef ctx) { std::cout << 3 << std::endl; LLVMContextRef global_context = LLVMGetGlobalContext(); is_global_context = global_context == context.get(); @@ -30,31 +30,31 @@ PyContext::PyContext(LLVMContextRef ctx) { } } -PyContext PyContext::getGlobalContext() { - return PyContext(LLVMGetGlobalContext(), true); +PymContext PymContext::getGlobalContext() { + return PymContext(LLVMGetGlobalContext(), true); } -LLVMContextRef PyContext::get() const { +LLVMContextRef PymContext::get() const { return context.get(); } -// NOTE don't store a pointer of parent in the Deleter, since when PyContext is +// NOTE don't store a pointer of parent in the Deleter, since when PymContext is // a derived class, it will cause object slicing problem, // also the stored parent object may be copied, since all the state in the `parent` object // is the state when we created LLVMContextDeleter object // These problems can possibly be handled by make parent field shared_ptr type, // but this makes things far more complex and ugly -void PyContext::LLVMContextDeleter::operator()(const LLVMContextRef context) const { +void PymContext::LLVMContextDeleter::operator()(const LLVMContextRef context) const { if (context) { - std::lock_guard lock(PyContext::map_mutex); - auto it = PyContext::context_map.find(context); + std::lock_guard lock(PymContext::map_mutex); + auto it = PymContext::context_map.find(context); - if (it != PyContext::context_map.end()) { + if (it != PymContext::context_map.end()) { LLVMContextDispose(context); - PyContext::context_map.erase(context); + PymContext::context_map.erase(context); } } } @@ -63,21 +63,21 @@ void PyContext::LLVMContextDeleter::operator()(const LLVMContextRef context) con /* * NOTE global context won't stored in context_map */ -std::shared_ptr PyContext::get_shared_context +std::shared_ptr PymContext::get_shared_context (LLVMContextRef context, bool is_global_context) { if (is_global_context) return std::shared_ptr(context, LLVMContextDeleter()); - std::lock_guard lock(PyContext::map_mutex); - auto it = PyContext::context_map.find(context); + std::lock_guard lock(PymContext::map_mutex); + auto it = PymContext::context_map.find(context); - if (it != PyContext::context_map.end()) { + if (it != PymContext::context_map.end()) { if (auto shared = it->second.lock()) { return shared; } } auto shared = std::shared_ptr(context, LLVMContextDeleter()); - PyContext::context_map[context] = shared; + PymContext::context_map[context] = shared; return shared; } diff --git a/src/llvm/types_priv/PyContext.h b/src/llvm/types_priv/PymContext.h similarity index 69% rename from src/llvm/types_priv/PyContext.h rename to src/llvm/types_priv/PymContext.h index c38c875..7c7f3e8 100644 --- a/src/llvm/types_priv/PyContext.h +++ b/src/llvm/types_priv/PymContext.h @@ -6,14 +6,14 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" -class PyContext : public PyLLVMObject { +class PymContext : public PymLLVMObject { public: - explicit PyContext(); - explicit PyContext(LLVMContextRef context, bool is_global_context); - explicit PyContext(LLVMContextRef context); - static PyContext getGlobalContext(); + explicit PymContext(); + explicit PymContext(LLVMContextRef context, bool is_global_context); + explicit PymContext(LLVMContextRef context); + static PymContext getGlobalContext(); LLVMContextRef get() const; diff --git a/src/llvm/types_priv/PyLLVMObject.h b/src/llvm/types_priv/PymLLVMObject.h similarity index 85% rename from src/llvm/types_priv/PyLLVMObject.h rename to src/llvm/types_priv/PymLLVMObject.h index 4047f0a..dcc9bdf 100644 --- a/src/llvm/types_priv/PyLLVMObject.h +++ b/src/llvm/types_priv/PymLLVMObject.h @@ -5,9 +5,9 @@ #include template -class PyLLVMObject { +class PymLLVMObject { public: - virtual ~PyLLVMObject() = default; + virtual ~PymLLVMObject() = default; UnderlyingType get() const { return const_cast(static_cast(this))->get(); @@ -20,7 +20,7 @@ class PyLLVMObject { } // `__equal__` and `__hash__` works well on pointer type UnderlyingType - bool __equal__(const PyLLVMObject& other) const { + bool __equal__(const PymLLVMObject& other) const { return this->get() == other.get(); } diff --git a/src/llvm/types_priv/PymMemoryBuffer.cpp b/src/llvm/types_priv/PymMemoryBuffer.cpp new file mode 100644 index 0000000..441f9a0 --- /dev/null +++ b/src/llvm/types_priv/PymMemoryBuffer.cpp @@ -0,0 +1,55 @@ +#include "PymMemoryBuffer.h" +#include + +std::unordered_map> PymMemoryBuffer::obj_map; +std::mutex PymMemoryBuffer::map_mutex; + +PymMemoryBuffer::PymMemoryBuffer(LLVMMemoryBufferRef obj) : obj(get_shared_obj(obj)) { } + +LLVMMemoryBufferRef PymMemoryBuffer::get() const { + return obj.get(); +} + +// This function doesn't call `reset` method on shared_ptr object, since +// it will then call deleter, which is undesired and will lead to crash. +void PymMemoryBuffer::reset() { + LLVMMemoryBufferRef m = obj.get(); + if (m) { + std::lock_guard lock(PymMemoryBuffer::map_mutex); + PymMemoryBuffer::obj_map.erase(m); + } +} + + +void PymMemoryBuffer::Deleter::operator() +(LLVMMemoryBufferRef mb) const { + if (mb) { + std::lock_guard lock(PymMemoryBuffer::map_mutex); + auto it = PymMemoryBuffer::obj_map.find(mb); + + // the logic here is specially designed for `reset` function + if (it != PymMemoryBuffer::obj_map.end()) { + LLVMDisposeMemoryBuffer(mb); + + PymMemoryBuffer::obj_map.erase(mb); + } + } +} + + +std::shared_ptr PymMemoryBuffer::get_shared_obj +(LLVMMemoryBufferRef mb) { + std::lock_guard lock(PymMemoryBuffer::map_mutex); + auto it = PymMemoryBuffer::obj_map.find(mb); + + if (it != PymMemoryBuffer::obj_map.end()) { + if (auto shared = it->second.lock()) { + return shared; + } + } + + auto shared = std::shared_ptr(mb, Deleter()); + PymMemoryBuffer::obj_map[mb] = shared; + return shared; +} diff --git a/src/llvm/types_priv/PyMemoryBuffer.h b/src/llvm/types_priv/PymMemoryBuffer.h similarity index 62% rename from src/llvm/types_priv/PyMemoryBuffer.h rename to src/llvm/types_priv/PymMemoryBuffer.h index acff4c0..0744b48 100644 --- a/src/llvm/types_priv/PyMemoryBuffer.h +++ b/src/llvm/types_priv/PymMemoryBuffer.h @@ -5,16 +5,16 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyMemoryBuffer : public PyLLVMObject { +class PymMemoryBuffer : public PymLLVMObject { public: - explicit PyMemoryBuffer(LLVMMemoryBufferRef mb); + explicit PymMemoryBuffer(LLVMMemoryBufferRef mb); LLVMMemoryBufferRef get() const; /* - * This function reset the PyMemoryBuffer object, preventing it from + * This function reset the PymMemoryBuffer object, preventing it from * being automatically disposed */ void reset(); diff --git a/src/llvm/types_priv/PymMetadataEntries.cpp b/src/llvm/types_priv/PymMetadataEntries.cpp new file mode 100644 index 0000000..79c21e5 --- /dev/null +++ b/src/llvm/types_priv/PymMetadataEntries.cpp @@ -0,0 +1,17 @@ +#include "PymMetadataEntries.h" + +PymMetadataEntries::PymMetadataEntries(LLVMValueMetadataEntries obj, size_t len) +: obj(get_shared_obj(obj)), len(len) { } + +LLVMValueMetadataEntries PymMetadataEntries::get() const { + return obj.get(); +} + +size_t PymMetadataEntries::getLen() const { + return len; +} + +SHARED_POINTER_IMPL(PymMetadataEntries, LLVMValueMetadataEntries, LLVMValueMetadataEntry, + LLVMDisposeValueMetadataEntries) + + diff --git a/src/llvm/types_priv/PyMetadataEntries.h b/src/llvm/types_priv/PymMetadataEntries.h similarity index 68% rename from src/llvm/types_priv/PyMetadataEntries.h rename to src/llvm/types_priv/PymMetadataEntries.h index 065c5df..c9ae126 100644 --- a/src/llvm/types_priv/PyMetadataEntries.h +++ b/src/llvm/types_priv/PymMetadataEntries.h @@ -5,14 +5,14 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" typedef LLVMValueMetadataEntry *LLVMValueMetadataEntries; -class PyMetadataEntries : public PyLLVMObject { +class PymMetadataEntries : public PymLLVMObject { public: - explicit PyMetadataEntries(LLVMValueMetadataEntries entries, size_t len); + explicit PymMetadataEntries(LLVMValueMetadataEntries entries, size_t len); LLVMValueMetadataEntries get() const; size_t getLen() const; diff --git a/src/llvm/types_priv/PyModule.cpp b/src/llvm/types_priv/PymModule.cpp similarity index 55% rename from src/llvm/types_priv/PyModule.cpp rename to src/llvm/types_priv/PymModule.cpp index f949215..65cc124 100644 --- a/src/llvm/types_priv/PyModule.cpp +++ b/src/llvm/types_priv/PymModule.cpp @@ -1,25 +1,25 @@ -#include "PyModule.h" +#include "PymModule.h" #include -PyModule::PyModule(const std::string &id) { +PymModule::PymModule(const std::string &id) { obj = get_shared_obj(LLVMModuleCreateWithName(id.c_str())); if (!obj) { throw std::runtime_error("Failed to create Module"); } } -PyModule::PyModule(const std::string &id, LLVMContextRef context) { +PymModule::PymModule(const std::string &id, LLVMContextRef context) { obj = get_shared_obj(LLVMModuleCreateWithNameInContext(id.c_str(), context)); if (!obj) { throw std::runtime_error("Failed to create Module"); } } -PyModule::PyModule(LLVMModuleRef obj) +PymModule::PymModule(LLVMModuleRef obj) : obj(get_shared_obj(obj)) { } -LLVMModuleRef PyModule::get() const { +LLVMModuleRef PymModule::get() const { return obj.get(); } -SHARED_POINTER_IMPL(PyModule, LLVMModuleRef, LLVMOpaqueModule, LLVMDisposeModule) +SHARED_POINTER_IMPL(PymModule, LLVMModuleRef, LLVMOpaqueModule, LLVMDisposeModule) diff --git a/src/llvm/types_priv/PyModule.h b/src/llvm/types_priv/PymModule.h similarity index 55% rename from src/llvm/types_priv/PyModule.h rename to src/llvm/types_priv/PymModule.h index f9ec049..d24e658 100644 --- a/src/llvm/types_priv/PyModule.h +++ b/src/llvm/types_priv/PymModule.h @@ -6,14 +6,14 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyModule : public PyLLVMObject { +class PymModule : public PymLLVMObject { public: - explicit PyModule(const std::string &id); - explicit PyModule(const std::string &id, LLVMContextRef context); - explicit PyModule(LLVMModuleRef module); + explicit PymModule(const std::string &id); + explicit PymModule(const std::string &id, LLVMContextRef context); + explicit PymModule(LLVMModuleRef module); LLVMModuleRef get() const; diff --git a/src/llvm/types_priv/PymModuleFlagEntries.cpp b/src/llvm/types_priv/PymModuleFlagEntries.cpp new file mode 100644 index 0000000..27d9745 --- /dev/null +++ b/src/llvm/types_priv/PymModuleFlagEntries.cpp @@ -0,0 +1,15 @@ +#include "PymModuleFlagEntries.h" + +PymModuleFlagEntries::PymModuleFlagEntries(LLVMModuleFlagEntries obj, size_t len) +: obj(get_shared_obj(obj)), len(len) { } + +LLVMModuleFlagEntries PymModuleFlagEntries::get() const { + return obj.get(); +} + +size_t PymModuleFlagEntries::getLen() const { + return len; +} + +SHARED_POINTER_IMPL(PymModuleFlagEntries, LLVMModuleFlagEntries, LLVMModuleFlagEntry, + LLVMDisposeModuleFlagsMetadata) diff --git a/src/llvm/types_priv/PyModuleFlagEntries.h b/src/llvm/types_priv/PymModuleFlagEntries.h similarity index 68% rename from src/llvm/types_priv/PyModuleFlagEntries.h rename to src/llvm/types_priv/PymModuleFlagEntries.h index e91bebd..3ed6162 100644 --- a/src/llvm/types_priv/PyModuleFlagEntries.h +++ b/src/llvm/types_priv/PymModuleFlagEntries.h @@ -5,14 +5,14 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" typedef LLVMModuleFlagEntry *LLVMModuleFlagEntries; -class PyModuleFlagEntries : public PyLLVMObject{ +class PymModuleFlagEntries : public PymLLVMObject{ public: - explicit PyModuleFlagEntries(LLVMModuleFlagEntries entries, size_t len); + explicit PymModuleFlagEntries(LLVMModuleFlagEntries entries, size_t len); LLVMModuleFlagEntries get() const; size_t getLen() const; diff --git a/src/llvm/types_priv/PymModuleProvider.cpp b/src/llvm/types_priv/PymModuleProvider.cpp new file mode 100644 index 0000000..2d2d91f --- /dev/null +++ b/src/llvm/types_priv/PymModuleProvider.cpp @@ -0,0 +1,11 @@ +#include "PymModuleProvider.h" + +PymModuleProvider::PymModuleProvider(LLVMModuleProviderRef obj) +: obj(get_shared_obj(obj)) {} + +LLVMModuleProviderRef PymModuleProvider::get() const { + return obj.get(); +} + +SHARED_POINTER_IMPL(PymModuleProvider, LLVMModuleProviderRef, LLVMOpaqueModuleProvider, + LLVMDisposeModuleProvider) diff --git a/src/llvm/types_priv/PyModuleProvider.h b/src/llvm/types_priv/PymModuleProvider.h similarity index 66% rename from src/llvm/types_priv/PyModuleProvider.h rename to src/llvm/types_priv/PymModuleProvider.h index 92195c5..e6170b5 100644 --- a/src/llvm/types_priv/PyModuleProvider.h +++ b/src/llvm/types_priv/PymModuleProvider.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyModuleProvider : public PyLLVMObject{ +class PymModuleProvider : public PymLLVMObject{ public: - explicit PyModuleProvider(LLVMModuleProviderRef mp); + explicit PymModuleProvider(LLVMModuleProviderRef mp); LLVMModuleProviderRef get() const; private: diff --git a/src/llvm/types_priv/PymOperandBundle.cpp b/src/llvm/types_priv/PymOperandBundle.cpp new file mode 100644 index 0000000..0769e89 --- /dev/null +++ b/src/llvm/types_priv/PymOperandBundle.cpp @@ -0,0 +1,13 @@ +#include "PymOperandBundle.h" + +PymOperandBundle::PymOperandBundle(LLVMOperandBundleRef obj) +: obj(get_shared_obj(obj)) { } + +LLVMOperandBundleRef PymOperandBundle::get() const { + return obj.get(); +} + + +SHARED_POINTER_IMPL(PymOperandBundle, LLVMOperandBundleRef, LLVMOpaqueOperandBundle, + LLVMDisposeOperandBundle) + diff --git a/src/llvm/types_priv/PyOperandBundle.h b/src/llvm/types_priv/PymOperandBundle.h similarity index 65% rename from src/llvm/types_priv/PyOperandBundle.h rename to src/llvm/types_priv/PymOperandBundle.h index 3ff8333..5e6f37d 100644 --- a/src/llvm/types_priv/PyOperandBundle.h +++ b/src/llvm/types_priv/PymOperandBundle.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyOperandBundle : public PyLLVMObject { +class PymOperandBundle : public PymLLVMObject { public: - explicit PyOperandBundle(LLVMOperandBundleRef bundle); + explicit PymOperandBundle(LLVMOperandBundleRef bundle); LLVMOperandBundleRef get() const; private: diff --git a/src/llvm/types_priv/PymPassManagerBase.cpp b/src/llvm/types_priv/PymPassManagerBase.cpp new file mode 100644 index 0000000..a4486fa --- /dev/null +++ b/src/llvm/types_priv/PymPassManagerBase.cpp @@ -0,0 +1,11 @@ +#include "PymPassManagerBase.h" + +PymPassManagerBase::PymPassManagerBase(LLVMPassManagerRef obj) +: obj(get_shared_obj(obj)) { } + +LLVMPassManagerRef PymPassManagerBase::get() const { + return obj.get(); +} + +SHARED_POINTER_IMPL(PymPassManagerBase, LLVMPassManagerRef, LLVMOpaquePassManager, + LLVMDisposePassManager) diff --git a/src/llvm/types_priv/PyPassManagerBase.h b/src/llvm/types_priv/PymPassManagerBase.h similarity index 65% rename from src/llvm/types_priv/PyPassManagerBase.h rename to src/llvm/types_priv/PymPassManagerBase.h index e94f0fb..96b3c3c 100644 --- a/src/llvm/types_priv/PyPassManagerBase.h +++ b/src/llvm/types_priv/PymPassManagerBase.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyPassManagerBase : public PyLLVMObject { +class PymPassManagerBase : public PymLLVMObject { public: - explicit PyPassManagerBase(LLVMPassManagerRef pm); + explicit PymPassManagerBase(LLVMPassManagerRef pm); LLVMPassManagerRef get() const; private: diff --git a/src/llvm/types_priv/PymTargetData.cpp b/src/llvm/types_priv/PymTargetData.cpp new file mode 100644 index 0000000..441d627 --- /dev/null +++ b/src/llvm/types_priv/PymTargetData.cpp @@ -0,0 +1,11 @@ +#include "PymTargetData.h" + +PymTargetData::PymTargetData(LLVMTargetDataRef data) +: obj(get_shared_obj(data)) {} + +LLVMTargetDataRef PymTargetData::get() const { + return obj.get(); +} + +SHARED_POINTER_IMPL(PymTargetData, LLVMTargetDataRef, LLVMOpaqueTargetData, + LLVMDisposeTargetData) diff --git a/src/llvm/types_priv/PyTargetData.h b/src/llvm/types_priv/PymTargetData.h similarity index 67% rename from src/llvm/types_priv/PyTargetData.h rename to src/llvm/types_priv/PymTargetData.h index b4f20e7..ed85564 100644 --- a/src/llvm/types_priv/PyTargetData.h +++ b/src/llvm/types_priv/PymTargetData.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyTargetData : public PyLLVMObject { +class PymTargetData : public PymLLVMObject { public: - explicit PyTargetData(LLVMTargetDataRef data); + explicit PymTargetData(LLVMTargetDataRef data); LLVMTargetDataRef get() const; private: diff --git a/src/llvm/types_priv/PymTargetMachine.cpp b/src/llvm/types_priv/PymTargetMachine.cpp new file mode 100644 index 0000000..fabff6a --- /dev/null +++ b/src/llvm/types_priv/PymTargetMachine.cpp @@ -0,0 +1,12 @@ +#include "PymTargetMachine.h" + +PymTargetMachine::PymTargetMachine(LLVMTargetMachineRef machine) +: obj(get_shared_obj(machine)) { } + +LLVMTargetMachineRef PymTargetMachine::get() const { + return obj.get(); +} + +SHARED_POINTER_IMPL(PymTargetMachine, LLVMTargetMachineRef, LLVMOpaqueTargetMachine, + LLVMDisposeTargetMachine) + diff --git a/src/llvm/types_priv/PyTargetMachine.h b/src/llvm/types_priv/PymTargetMachine.h similarity index 66% rename from src/llvm/types_priv/PyTargetMachine.h rename to src/llvm/types_priv/PymTargetMachine.h index 76b72f0..dda53ee 100644 --- a/src/llvm/types_priv/PyTargetMachine.h +++ b/src/llvm/types_priv/PymTargetMachine.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyTargetMachine : public PyLLVMObject { +class PymTargetMachine : public PymLLVMObject { public: - explicit PyTargetMachine(LLVMTargetMachineRef machine); + explicit PymTargetMachine(LLVMTargetMachineRef machine); LLVMTargetMachineRef get() const; private: diff --git a/src/llvm/types_priv/PymTargetMachineOptions.cpp b/src/llvm/types_priv/PymTargetMachineOptions.cpp new file mode 100644 index 0000000..ffe0ab2 --- /dev/null +++ b/src/llvm/types_priv/PymTargetMachineOptions.cpp @@ -0,0 +1,12 @@ +#include "PymTargetMachineOptions.h" + +PymTargetMachineOptions::PymTargetMachineOptions(LLVMTargetMachineOptionsRef obj) +: obj(get_shared_obj(obj)) {} + +LLVMTargetMachineOptionsRef PymTargetMachineOptions::get() const { + return obj.get(); +} + + +SHARED_POINTER_IMPL(PymTargetMachineOptions, LLVMTargetMachineOptionsRef, + LLVMOpaqueTargetMachineOptions, LLVMDisposeTargetMachineOptions) diff --git a/src/llvm/types_priv/PyTargetMachineOptions.h b/src/llvm/types_priv/PymTargetMachineOptions.h similarity index 64% rename from src/llvm/types_priv/PyTargetMachineOptions.h rename to src/llvm/types_priv/PymTargetMachineOptions.h index 1268e75..89621c8 100644 --- a/src/llvm/types_priv/PyTargetMachineOptions.h +++ b/src/llvm/types_priv/PymTargetMachineOptions.h @@ -5,12 +5,12 @@ #include #include #include -#include "PyLLVMObject.h" +#include "PymLLVMObject.h" #include "utils.h" -class PyTargetMachineOptions : public PyLLVMObject { +class PymTargetMachineOptions : public PymLLVMObject { public: - explicit PyTargetMachineOptions(LLVMTargetMachineOptionsRef machine); + explicit PymTargetMachineOptions(LLVMTargetMachineOptionsRef machine); LLVMTargetMachineOptionsRef get() const; private: diff --git a/src/llvmpym_ext.cpp b/src/llvmpym_ext.cpp index ca3be61..71c32be 100644 --- a/src/llvmpym_ext.cpp +++ b/src/llvmpym_ext.cpp @@ -13,7 +13,7 @@ using namespace nb::literals; NB_MODULE(llvmpym_ext, m) { - m.doc() = "LLVM Python Native Extension"; + m.doc() = "LLVM Pymthon Native Extension"; BIND_PYLLVMOBJECT();