Skip to content

Commit

Permalink
feat: add Support module
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziqi-Yang committed Aug 4, 2024
1 parent d497a40 commit 4576fb0
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/llvm/Support.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <nanobind/nanobind.h>
#include <nanobind/stl/vector.h>
#include <vector>
#include <llvm-c/Support.h>


namespace nb = nanobind;
using namespace nb::literals;

void populateSupport(nb::module_ &m) {

m.def("load_library_permanently",
[](const char *filename) {
return LLVMLoadLibraryPermanently(filename) != 0;
Expand All @@ -14,8 +16,34 @@ void populateSupport(nb::module_ &m) {
"This function permanently loads the dynamic library at the given path."
"It is safe to call this function multiple times for the same library.");

// m.def("parse_command_line_options",
// [](std::vector<std::string> &args, const char *overview) {
// return LLVMParseCommandLineOptions(args.size(), args.data(), )
// })
m.def("parse_command_line_options",
[](const std::vector<const char*> &args, const char *overview) {
LLVMParseCommandLineOptions(args.size(), args.data(), overview);
},
"args"_a, "overview"_a,
"This function parses the given arguments using the LLVM command line parser."
"Note that the only stable thing about this function is its signature; you"
"cannot rely on any particular set of command line arguments being interpreted"
"the same way across LLVM versions.");


// FIXME seems not practical in python side
// m.def("search_for_address_of_symbol",
// [](const char *symbolName) {
// return LLVMSearchForAddressOfSymbol(symbolName);
// },
// "name"_a,
// "This function will search through all previously loaded dynamic"
// "libraries for the symbol symbolName. If it is found, the address of"
// "that symbol is returned. If not, null is returned.");

// m.def("add_symbol",
// [](const char *symbolName, nb::any symbolValue) {
// // the passed value is nb::any*, but not void *
// return LLVMAddSymbol(symbolName, &symbolValue);
// },
// "symbol_name"_a, "symbol_value"_a,
// "This functions permanently adds the symbol symbolName with the"
// "value symbolValue. These symbols are searched before any"
// "libraries.");
}

0 comments on commit 4576fb0

Please sign in to comment.