Skip to content

Commit

Permalink
feat: add object module (part)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziqi-Yang committed Aug 17, 2024
1 parent 70c3287 commit ee86f4d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ nanobind_add_stub(
DEPENDS llvmpym_ext
)

nanobind_add_stub(
llvmpym_ext_stub_object
MODULE llvmpym_ext.object
OUTPUT object.pyi
PYTHON_PATH $<TARGET_FILE_DIR:llvmpym_ext>
DEPENDS llvmpym_ext
)


# Install directive for scikit-build-core
install(TARGETS llvmpym_ext LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
Expand All @@ -255,5 +263,6 @@ install(FILES
${CMAKE_BINARY_DIR}/bit_reader.pyi
${CMAKE_BINARY_DIR}/disassembler.pyi
${CMAKE_BINARY_DIR}/linker.pyi
${CMAKE_BINARY_DIR}/object.pyi

DESTINATION ${SKBUILD_PROJECT_NAME}/llvmpym_ext)
61 changes: 61 additions & 0 deletions src/llvm/Object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "Object.h"

#include <nanobind/nanobind.h>
#include <llvm-c/Object.h>
#include <stdexcept>
#include "types_priv.h"

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

void populateObject(nb::module_ &m) {
nb::enum_<LLVMBinaryType>(m, "BinaryType", "BinaryType")
.value("LLVMBinaryTypeArchive",
LLVMBinaryType::LLVMBinaryTypeArchive,
"Archive file.")
.value("LLVMBinaryTypeMachOUniversalBinary",
LLVMBinaryType::LLVMBinaryTypeMachOUniversalBinary,
"Mach-O Universal Binary file.")
.value("LLVMBinaryTypeCOFFImportFile",
LLVMBinaryType::LLVMBinaryTypeCOFFImportFile,
"COFF Import file.")
.value("LLVMBinaryTypeIR",
LLVMBinaryType::LLVMBinaryTypeIR,
"LLVM IR.")
.value("LLVMBinaryTypeWinRes",
LLVMBinaryType::LLVMBinaryTypeWinRes,
"Windows resource (.res) file.")
.value("LLVMBinaryTypeCOFF",
LLVMBinaryType::LLVMBinaryTypeCOFF,
"COFF Object file.")
.value("LLVMBinaryTypeELF32L",
LLVMBinaryType::LLVMBinaryTypeELF32L,
"ELF 32-bit, little endian.")
.value("LLVMBinaryTypeELF32B",
LLVMBinaryType::LLVMBinaryTypeELF32B,
"ELF 32-bit, big endian.")
.value("LLVMBinaryTypeELF64L",
LLVMBinaryType::LLVMBinaryTypeELF64L,
"ELF 64-bit, little endian.")
.value("LLVMBinaryTypeELF64B",
LLVMBinaryType::LLVMBinaryTypeELF64B,
"ELF 64-bit, big endian.")
.value("LLVMBinaryTypeMachO32L",
LLVMBinaryType::LLVMBinaryTypeMachO32L,
"MachO 32-bit, little endian.")
.value("LLVMBinaryTypeMachO32B",
LLVMBinaryType::LLVMBinaryTypeMachO32B,
"MachO 32-bit, big endian.")
.value("LLVMBinaryTypeMachO64L",
LLVMBinaryType::LLVMBinaryTypeMachO64L,
"MachO 64-bit, little endian.")
.value("LLVMBinaryTypeMachO64B",
LLVMBinaryType::LLVMBinaryTypeMachO64B,
"MachO 64-bit, big endian.")
.value("LLVMBinaryTypeWasm",
LLVMBinaryType::LLVMBinaryTypeWasm,
"Web Assembly.")
.value("LLVMBinaryTypeOffload",
LLVMBinaryType::LLVMBinaryTypeOffload,
"Offloading fatbinary.");
}
10 changes: 10 additions & 0 deletions src/llvm/Object.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LLVMPYM_OBJECT_H
#define LLVMPYM_OBJECT_H

#include <nanobind/nanobind.h>

void populateObject(nanobind::module_ &m);



#endif
1 change: 1 addition & 0 deletions src/llvmpym/object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .llvmpym_ext.object import *
3 changes: 3 additions & 0 deletions src/llvmpym_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "llvm/Disassembler.h"
#include "llvm/BitReader.h"
#include "llvm/Linker.h"
#include "llvm/Object.h"

namespace nb = nanobind;
using namespace nb::literals;
Expand Down Expand Up @@ -51,4 +52,6 @@ NB_MODULE(llvmpym_ext, m) {
auto linkerModule = m.def_submodule("linker", "linker");
populateLinker(linkerModule);

auto objectModule = m.def_submodule("object", "object");
populateObject(objectModule);
}

0 comments on commit ee86f4d

Please sign in to comment.