Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 16 #55

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ package-lock.json
test/temp/

/**/**/.DS_Store
cmake_install.cmake
cmake_install.cmake
llvm-bindings.d.ts
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.17)

project(llvm-bindings)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

set(CMAKE_CXX_STANDARD 17)

Expand All @@ -26,8 +27,29 @@ execute_process(

string(REGEX REPLACE "[\r\n\"]" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})

# Add a library to generate the TypeScript declarations
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/llvm-bindings.d.ts.cpp
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/llvm-bindings.in.d.ts
${CMAKE_CURRENT_BINARY_DIR}/llvm-bindings.d.ts.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/llvm-bindings.in.d.ts
)
add_library(ts_decl_lib OBJECT ${CMAKE_CURRENT_BINARY_DIR}/llvm-bindings.d.ts.cpp)
target_link_libraries(ts_decl_lib ${LLVM_LIBS})
target_compile_options(ts_decl_lib PRIVATE -E -P --traditional-cpp)
target_include_directories(ts_decl_lib PRIVATE ${LLVM_INCLUDE_DIRS})

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} ${NODE_ADDON_API_DIR})

target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${LLVM_LIBS})

add_definitions(-DNAPI_VERSION=8)

add_custom_target(
ts_declarations
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_OBJECTS:ts_decl_lib>" ${CMAKE_CURRENT_SOURCE_DIR}/llvm-bindings.d.ts
DEPENDS ts_decl_lib
)

add_dependencies(${PROJECT_NAME} ts_declarations)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Due to the limitation of `node-addon-api`, this project has not implemented inhe
| 0.2.x | 12.0.x |
| 0.3.x | 13.0.x |
| 0.4.x | 14.0.x |
| 0.5.x | 16.0.x |

## Acknowledgments
- [MichaReiser](https://github.com/MichaReiser): the creator of [llvm-node](https://github.com/MichaReiser/llvm-node)
Expand Down
14 changes: 6 additions & 8 deletions cmake/CMakeJS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ endfunction(GET_VARIABLE)
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)

if (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
exec_program(
${CMakeJS}
${CMAKE_CURRENT_SOURCE_DIR}
ARGS print-configure --debug
execute_process(
COMMAND ${CMakeJS} print-configure --debug
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_JS_OUTPUT
)
else ()
exec_program(
${CMakeJS}
${CMAKE_CURRENT_SOURCE_DIR}
ARGS print-configure
execute_process(
COMMAND ${CMakeJS} print-configure
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_JS_OUTPUT
)
endif ()
Expand Down
2 changes: 1 addition & 1 deletion cmake/LLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (CMAKE_HOST_APPLE)
endforeach ()
endif ()

find_package(LLVM 14 REQUIRED CONFIG)
find_package(LLVM 16 REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")

Expand Down
2 changes: 1 addition & 1 deletion include/IR/DerivedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,5 @@ class PointerType : public Napi::ObjectWrap<PointerType> {

Napi::Value getTypeID(const Napi::CallbackInfo &info);

Napi::Value getPointerElementType(const Napi::CallbackInfo &info);
Napi::Value getNonOpaquePointerElementType(const Napi::CallbackInfo &info);
};
2 changes: 1 addition & 1 deletion include/IR/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Type : public Napi::ObjectWrap<Type> {
return Napi::Boolean::New(info.Env(), (type->*method)());
}

Napi::Value getPointerElementType(const Napi::CallbackInfo &info);
Napi::Value getNonOpaquePointerElementType(const Napi::CallbackInfo &info);

static Napi::Value isSameType(const Napi::CallbackInfo &info);
};
13 changes: 13 additions & 0 deletions include/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __LLVM_BINDINGS_NODEJS_ASSERT__
#define __LLVM_BINDINGS_NODEJS_ASSERT__

#ifdef __cplusplus
void llvm_bindings_assert(const char* expr, const char* file, int line);

#define __assert(e, file, line) ((void)llvm_bindings_assert ((e), (file), (line)))

#define assert(e) ((void) ((e) ? ((void)0) : __assert (#e, __FILE__, __LINE__)))

#endif

#endif
93 changes: 11 additions & 82 deletions llvm-bindings.d.ts → llvm-bindings.in.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,86 +98,13 @@ declare namespace llvm {

class Attribute {
public static readonly AttrKind: {
AlwaysInline: number;
ArgMemOnly: number;
Builtin: number;
Cold: number;
Convergent: number;
DisableSanitizerInstrumentation: number;
Hot: number;
ImmArg: number;
InReg: number;
InaccessibleMemOnly: number;
InaccessibleMemOrArgMemOnly: number;
InlineHint: number;
JumpTable: number;
MinSize: number;
MustProgress: number;
Naked: number;
Nest: number;
NoAlias: number;
NoBuiltin: number;
NoCallback: number;
NoCapture: number;
NoCfCheck: number;
NoDuplicate: number;
NoFree: number;
NoImplicitFloat: number;
NoInline: number;
NoMerge: number;
NoProfile: number;
NoRecurse: number;
NoRedZone: number;
NoReturn: number;
NoSanitizeCoverage: number;
NoSync: number;
NoUndef: number;
NoUnwind: number;
NonLazyBind: number;
NonNull: number;
NullPointerIsValid: number;
OptForFuzzing: number;
OptimizeForSize: number;
OptimizeNone: number;
ReadNone: number;
ReadOnly: number;
Returned: number;
ReturnsTwice: number;
SExt: number;
SafeStack: number;
SanitizeAddress: number;
SanitizeHWAddress: number;
SanitizeMemTag: number;
SanitizeMemory: number;
SanitizeThread: number;
ShadowCallStack: number;
Speculatable: number;
SpeculativeLoadHardening: number;
StackProtect: number;
StackProtectReq: number;
StackProtectStrong: number;
StrictFP: number;
SwiftAsync: number;
SwiftError: number;
SwiftSelf: number;
UWTable: number;
WillReturn: number;
WriteOnly: number;
LastEnumAttr: number;
ByRef: number;
ByVal: number;
ElementType: number;
InAlloca: number;
Preallocated: number;
LastTypeAttr: number;
Alignment: number;
AllocSize: number;
Dereferenceable: number;
DereferenceableOrNull: number;
StackAlignment: number;
VScaleRange: number;
};

#define GET_ATTR_NAMES
#define ATTRIBUTE_ENUM(EnumName, lower) \
EnumName: number;
#include "llvm/IR/Attributes.inc"

};
public static get(context: LLVMContext, kind: number, value?: number): Attribute;
public static get(context: LLVMContext, kind: string, value?: string): Attribute;
public static get(context: LLVMContext, kind: number, type: Type): Attribute;
Expand Down Expand Up @@ -374,7 +301,7 @@ declare namespace llvm {

public getPrimitiveSizeInBits(): number;

public getPointerElementType(): Type;
public getNonOpaquePointerElementType(): Type;

// extra
public static isSameType(type1: Type, type2: Type): boolean;
Expand Down Expand Up @@ -516,8 +443,10 @@ declare namespace llvm {
// duplicated
public getTypeID(): number;

// duplicated
public getPointerElementType(): Type;
/**
* @deprecated In LLVM 15,16 these are deprecated. LLVM 17 this is removed
*/
public getNonOpaquePointerElementType(): Type;

protected constructor();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "llvm-bindings",
"version": "0.4.2",
"version": "0.5.0",
"description": "LLVM bindings for Node.js/JavaScript/TypeScript",
"keywords": [
"llvm",
Expand Down
86 changes: 4 additions & 82 deletions src/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,10 @@ void Attribute::Init(Napi::Env env, Napi::Object &exports) {
Napi::HandleScope scope(env);

Napi::Object attributeKinds = Napi::Object::New(env);
attributeKinds.Set("AlwaysInline", Napi::Number::New(env, llvm::Attribute::AttrKind::AlwaysInline));
attributeKinds.Set("ArgMemOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::ArgMemOnly));
attributeKinds.Set("Builtin", Napi::Number::New(env, llvm::Attribute::AttrKind::Builtin));
attributeKinds.Set("Cold", Napi::Number::New(env, llvm::Attribute::AttrKind::Cold));
attributeKinds.Set("Convergent", Napi::Number::New(env, llvm::Attribute::AttrKind::Convergent));
attributeKinds.Set("DisableSanitizerInstrumentation",
Napi::Number::New(env, llvm::Attribute::AttrKind::DisableSanitizerInstrumentation));
attributeKinds.Set("Hot", Napi::Number::New(env, llvm::Attribute::AttrKind::Hot));
attributeKinds.Set("ImmArg", Napi::Number::New(env, llvm::Attribute::AttrKind::ImmArg));
attributeKinds.Set("InReg", Napi::Number::New(env, llvm::Attribute::AttrKind::InReg));
attributeKinds.Set("InaccessibleMemOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::InaccessibleMemOnly));
attributeKinds.Set("InaccessibleMemOrArgMemOnly",
Napi::Number::New(env, llvm::Attribute::AttrKind::InaccessibleMemOrArgMemOnly));
attributeKinds.Set("InlineHint", Napi::Number::New(env, llvm::Attribute::AttrKind::InlineHint));
attributeKinds.Set("JumpTable", Napi::Number::New(env, llvm::Attribute::AttrKind::JumpTable));
attributeKinds.Set("MinSize", Napi::Number::New(env, llvm::Attribute::AttrKind::MinSize));
attributeKinds.Set("MustProgress", Napi::Number::New(env, llvm::Attribute::AttrKind::MustProgress));
attributeKinds.Set("Naked", Napi::Number::New(env, llvm::Attribute::AttrKind::Naked));
attributeKinds.Set("Nest", Napi::Number::New(env, llvm::Attribute::AttrKind::Nest));
attributeKinds.Set("NoAlias", Napi::Number::New(env, llvm::Attribute::AttrKind::NoAlias));
attributeKinds.Set("NoBuiltin", Napi::Number::New(env, llvm::Attribute::AttrKind::NoBuiltin));
attributeKinds.Set("NoCallback", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCallback));
attributeKinds.Set("NoCapture", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCapture));
attributeKinds.Set("NoCfCheck", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCfCheck));
attributeKinds.Set("NoDuplicate", Napi::Number::New(env, llvm::Attribute::AttrKind::NoDuplicate));
attributeKinds.Set("NoFree", Napi::Number::New(env, llvm::Attribute::AttrKind::NoFree));
attributeKinds.Set("NoImplicitFloat", Napi::Number::New(env, llvm::Attribute::AttrKind::NoImplicitFloat));
attributeKinds.Set("NoInline", Napi::Number::New(env, llvm::Attribute::AttrKind::NoInline));
attributeKinds.Set("NoMerge", Napi::Number::New(env, llvm::Attribute::AttrKind::NoMerge));
attributeKinds.Set("NoProfile", Napi::Number::New(env, llvm::Attribute::AttrKind::NoProfile));
attributeKinds.Set("NoRecurse", Napi::Number::New(env, llvm::Attribute::AttrKind::NoRecurse));
attributeKinds.Set("NoRedZone", Napi::Number::New(env, llvm::Attribute::AttrKind::NoRedZone));
attributeKinds.Set("NoReturn", Napi::Number::New(env, llvm::Attribute::AttrKind::NoReturn));
attributeKinds.Set("NoSanitizeCoverage", Napi::Number::New(env, llvm::Attribute::AttrKind::NoSanitizeCoverage));
attributeKinds.Set("NoSync", Napi::Number::New(env, llvm::Attribute::AttrKind::NoSync));
attributeKinds.Set("NoUndef", Napi::Number::New(env, llvm::Attribute::AttrKind::NoUndef));
attributeKinds.Set("NoUnwind", Napi::Number::New(env, llvm::Attribute::AttrKind::NoUnwind));
attributeKinds.Set("NonLazyBind", Napi::Number::New(env, llvm::Attribute::AttrKind::NonLazyBind));
attributeKinds.Set("NonNull", Napi::Number::New(env, llvm::Attribute::AttrKind::NonNull));
attributeKinds.Set("NullPointerIsValid", Napi::Number::New(env, llvm::Attribute::AttrKind::NullPointerIsValid));
attributeKinds.Set("OptForFuzzing", Napi::Number::New(env, llvm::Attribute::AttrKind::OptForFuzzing));
attributeKinds.Set("OptimizeForSize", Napi::Number::New(env, llvm::Attribute::AttrKind::OptimizeForSize));
attributeKinds.Set("OptimizeNone", Napi::Number::New(env, llvm::Attribute::AttrKind::OptimizeNone));
attributeKinds.Set("ReadNone", Napi::Number::New(env, llvm::Attribute::AttrKind::ReadNone));
attributeKinds.Set("ReadOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::ReadOnly));
attributeKinds.Set("Returned", Napi::Number::New(env, llvm::Attribute::AttrKind::Returned));
attributeKinds.Set("ReturnsTwice", Napi::Number::New(env, llvm::Attribute::AttrKind::ReturnsTwice));
attributeKinds.Set("SExt", Napi::Number::New(env, llvm::Attribute::AttrKind::SExt));
attributeKinds.Set("SafeStack", Napi::Number::New(env, llvm::Attribute::AttrKind::SafeStack));
attributeKinds.Set("SanitizeAddress", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeAddress));
attributeKinds.Set("SanitizeHWAddress", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeHWAddress));
attributeKinds.Set("SanitizeMemTag", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeMemTag));
attributeKinds.Set("SanitizeMemory", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeMemory));
attributeKinds.Set("SanitizeThread", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeThread));
attributeKinds.Set("ShadowCallStack", Napi::Number::New(env, llvm::Attribute::AttrKind::ShadowCallStack));
attributeKinds.Set("Speculatable", Napi::Number::New(env, llvm::Attribute::AttrKind::Speculatable));
attributeKinds.Set("SpeculativeLoadHardening",
Napi::Number::New(env, llvm::Attribute::AttrKind::SpeculativeLoadHardening));
attributeKinds.Set("StackProtect", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtect));
attributeKinds.Set("StackProtectReq", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtectReq));
attributeKinds.Set("StackProtectStrong", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtectStrong));
attributeKinds.Set("StrictFP", Napi::Number::New(env, llvm::Attribute::AttrKind::StrictFP));
attributeKinds.Set("SwiftAsync", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftAsync));
attributeKinds.Set("SwiftError", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftError));
attributeKinds.Set("SwiftSelf", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftSelf));
attributeKinds.Set("UWTable", Napi::Number::New(env, llvm::Attribute::AttrKind::UWTable));
attributeKinds.Set("WillReturn", Napi::Number::New(env, llvm::Attribute::AttrKind::WillReturn));
attributeKinds.Set("WriteOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::WriteOnly));
attributeKinds.Set("LastEnumAttr", Napi::Number::New(env, llvm::Attribute::AttrKind::LastEnumAttr));
attributeKinds.Set("ByRef", Napi::Number::New(env, llvm::Attribute::AttrKind::ByRef));
attributeKinds.Set("ByVal", Napi::Number::New(env, llvm::Attribute::AttrKind::ByVal));
attributeKinds.Set("ElementType", Napi::Number::New(env, llvm::Attribute::AttrKind::ElementType));
attributeKinds.Set("InAlloca", Napi::Number::New(env, llvm::Attribute::AttrKind::InAlloca));
attributeKinds.Set("Preallocated", Napi::Number::New(env, llvm::Attribute::AttrKind::Preallocated));
attributeKinds.Set("LastTypeAttr", Napi::Number::New(env, llvm::Attribute::AttrKind::LastTypeAttr));
attributeKinds.Set("Alignment", Napi::Number::New(env, llvm::Attribute::AttrKind::Alignment));
attributeKinds.Set("AllocSize", Napi::Number::New(env, llvm::Attribute::AttrKind::AllocSize));
attributeKinds.Set("Dereferenceable", Napi::Number::New(env, llvm::Attribute::AttrKind::Dereferenceable));
attributeKinds.Set("DereferenceableOrNull",
Napi::Number::New(env, llvm::Attribute::AttrKind::DereferenceableOrNull));
attributeKinds.Set("StackAlignment", Napi::Number::New(env, llvm::Attribute::AttrKind::StackAlignment));
attributeKinds.Set("VScaleRange", Napi::Number::New(env, llvm::Attribute::AttrKind::VScaleRange));

#define GET_ATTR_NAMES
#define ATTRIBUTE_ENUM(EnumName, lower) attributeKinds.Set(#EnumName, Napi::Number::New(env, llvm::Attribute::AttrKind::EnumName));
#include "llvm/IR/Attributes.inc"

Napi::Function func = DefineClass(env, "Attribute", {
StaticValue("AttrKind", attributeKinds),
Expand Down
2 changes: 1 addition & 1 deletion src/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Napi::Value DataLayout::getTypeAllocSize(const Napi::CallbackInfo &info) {
if (info.Length() == 1 && Type::IsClassOf(info[0])) {
llvm::Type *type = Type::Extract(info[0]);
auto allocSize = dataLayout->getTypeAllocSize(type);
return Napi::Number::New(env, double(allocSize.getFixedSize()));
return Napi::Number::New(env, static_cast<double>(allocSize.getFixedValue()));
}
throw Napi::TypeError::New(env, ErrMsg::Class::DataLayout::getTypeAllocSize);
}
6 changes: 3 additions & 3 deletions src/IR/DerivedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ void PointerType::Init(Napi::Env env, Napi::Object &exports) {
InstanceMethod("isIntegerTy", &PointerType::isIntegerTy),
InstanceMethod("isVoidTy", &PointerType::isVoidTy),
InstanceMethod("getTypeID", &PointerType::getTypeID),
InstanceMethod("getPointerElementType", &PointerType::getPointerElementType)
InstanceMethod("getNonOpaquePointerElementType", &PointerType::getNonOpaquePointerElementType)
});
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
Expand Down Expand Up @@ -647,6 +647,6 @@ Napi::Value PointerType::getTypeID(const Napi::CallbackInfo &info) {
return Napi::Number::New(info.Env(), pointerType->getTypeID());
}

Napi::Value PointerType::getPointerElementType(const Napi::CallbackInfo &info) {
return Type::New(info.Env(), pointerType->getPointerElementType());
Napi::Value PointerType::getNonOpaquePointerElementType(const Napi::CallbackInfo &info) {
return Type::New(info.Env(), pointerType->getNonOpaquePointerElementType());
}
4 changes: 2 additions & 2 deletions src/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Function::addBasicBlock(const Napi::CallbackInfo &info) {
throw Napi::TypeError::New(env, ErrMsg::Class::Function::addBasicBlock);
}
llvm::BasicBlock *basicBlock = BasicBlock::Extract(info[0]);
function->getBasicBlockList().push_back(basicBlock);
function->insert(function->end(), basicBlock);
}

Napi::Value Function::getEntryBlock(const Napi::CallbackInfo &info) {
Expand All @@ -129,7 +129,7 @@ void Function::insertAfter(const Napi::CallbackInfo &info) {
}
llvm::BasicBlock *where = BasicBlock::Extract(info[0]);
llvm::BasicBlock *bb = BasicBlock::Extract(info[1]);
function->getBasicBlockList().insertAfter(where->getIterator(), bb);
function->insert(where->getIterator(), bb);
}

void Function::deleteBody(const Napi::CallbackInfo &info) {
Expand Down
Loading
Loading