@designliquido/llvm-bindings 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +10 -0
- package/.github/dependabot.yml +12 -0
- package/.github/workflows/build.yml +156 -0
- package/.release-it.json +11 -0
- package/CHANGELOG.md +2 -0
- package/CMakeLists.txt +40 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +13 -0
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/cmake/CMakeJS.cmake +57 -0
- package/cmake/LLVM.cmake +18 -0
- package/dist/index.js +4 -0
- package/include/ADT/APFloat.h +22 -0
- package/include/ADT/APInt.h +22 -0
- package/include/ADT/index.h +7 -0
- package/include/BinaryFormat/Dwarf.h +8 -0
- package/include/BinaryFormat/index.h +6 -0
- package/include/Bitcode/BitcodeWriter.h +6 -0
- package/include/Bitcode/index.h +6 -0
- package/include/Config/index.h +6 -0
- package/include/Config/llvm-config.h +6 -0
- package/include/IR/Argument.h +32 -0
- package/include/IR/Attributes.h +26 -0
- package/include/IR/BasicBlock.h +46 -0
- package/include/IR/Constant.h +36 -0
- package/include/IR/Constants.h +200 -0
- package/include/IR/DIBuilder.h +54 -0
- package/include/IR/DataLayout.h +28 -0
- package/include/IR/DebugInfoMetadata.h +408 -0
- package/include/IR/DebugLoc.h +24 -0
- package/include/IR/DerivedTypes.h +232 -0
- package/include/IR/Function.h +72 -0
- package/include/IR/GlobalObject.h +28 -0
- package/include/IR/GlobalValue.h +28 -0
- package/include/IR/GlobalVariable.h +36 -0
- package/include/IR/IRBuilder.h +280 -0
- package/include/IR/Instruction.h +36 -0
- package/include/IR/Instructions.h +1150 -0
- package/include/IR/Intrinsic.h +8 -0
- package/include/IR/LLVMContext.h +22 -0
- package/include/IR/Metadata.h +48 -0
- package/include/IR/Module.h +56 -0
- package/include/IR/Type.h +45 -0
- package/include/IR/User.h +32 -0
- package/include/IR/Value.h +40 -0
- package/include/IR/Verifier.h +8 -0
- package/include/IR/index.h +30 -0
- package/include/IRReader/IRReader.h +6 -0
- package/include/IRReader/index.h +6 -0
- package/include/Linker/Linker.h +20 -0
- package/include/Linker/index.h +6 -0
- package/include/MC/TargetRegistry.h +26 -0
- package/include/MC/index.h +6 -0
- package/include/Support/SourceMgr.h +22 -0
- package/include/Support/TargetSelect.h +6 -0
- package/include/Support/index.h +7 -0
- package/include/Target/TargetMachine.h +22 -0
- package/include/Target/index.h +6 -0
- package/include/Util/Array.h +39 -0
- package/include/Util/ErrMsg.h +586 -0
- package/include/Util/Inherit.h +5 -0
- package/include/Util/index.h +5 -0
- package/index.ts +5 -0
- package/llvm-bindings.d.ts +2233 -0
- package/package.json +72 -0
- package/src/ADT/APFloat.cpp +31 -0
- package/src/ADT/APInt.cpp +37 -0
- package/src/ADT/index.cpp +6 -0
- package/src/BinaryFormat/Dwarf.cpp +76 -0
- package/src/BinaryFormat/index.cpp +5 -0
- package/src/Bitcode/BitcodeWriter.cpp +27 -0
- package/src/Bitcode/index.cpp +5 -0
- package/src/Config/index.cpp +5 -0
- package/src/Config/llvm-config.cpp +19 -0
- package/src/IR/Argument.cpp +92 -0
- package/src/IR/Attributes.cpp +174 -0
- package/src/IR/BasicBlock.cpp +151 -0
- package/src/IR/Constants.cpp +686 -0
- package/src/IR/DIBuilder.cpp +328 -0
- package/src/IR/DataLayout.cpp +59 -0
- package/src/IR/DebugInfoMetadata.cpp +961 -0
- package/src/IR/DebugLoc.cpp +44 -0
- package/src/IR/DerivedTypes.cpp +652 -0
- package/src/IR/Function.cpp +279 -0
- package/src/IR/GlobalObject.cpp +59 -0
- package/src/IR/GlobalValue.cpp +75 -0
- package/src/IR/GlobalVariable.cpp +122 -0
- package/src/IR/IRBuilder.cpp +843 -0
- package/src/IR/Instruction.cpp +190 -0
- package/src/IR/Instructions.cpp +2866 -0
- package/src/IR/Intrinsic.cpp +352 -0
- package/src/IR/LLVMContext.cpp +30 -0
- package/src/IR/Metadata.cpp +107 -0
- package/src/IR/Module.cpp +228 -0
- package/src/IR/Type.cpp +278 -0
- package/src/IR/User.cpp +81 -0
- package/src/IR/Value.cpp +103 -0
- package/src/IR/Verifier.cpp +28 -0
- package/src/IR/index.cpp +108 -0
- package/src/IRReader/IRReader.cpp +19 -0
- package/src/IRReader/index.cpp +5 -0
- package/src/Linker/Linker.cpp +45 -0
- package/src/Linker/index.cpp +5 -0
- package/src/MC/TargetRegistry.cpp +88 -0
- package/src/MC/index.cpp +6 -0
- package/src/Support/SourceMgr.cpp +31 -0
- package/src/Support/TargetSelect.cpp +54 -0
- package/src/Support/index.cpp +6 -0
- package/src/Target/TargetMachine.cpp +37 -0
- package/src/Target/index.cpp +5 -0
- package/src/Util/Inherit.cpp +13 -0
- package/src/llvm-bindings.cpp +26 -0
- package/test/add.ts +32 -0
- package/test/attribute.ts +37 -0
- package/test/bitcode/add.bc +0 -0
- package/test/bitcodeWriter.ts +44 -0
- package/test/class.ts +39 -0
- package/test/debugInfo.ts +181 -0
- package/test/exception.ts +57 -0
- package/test/fibonacci.ts +44 -0
- package/test/gep.ts +42 -0
- package/test/index.ts +33 -0
- package/test/intrinsic.ts +35 -0
- package/test/linker.ts +48 -0
- package/test/str.ts +19 -0
- package/test/switch.ts +58 -0
- package/test/target.ts +14 -0
- package/test/type.ts +21 -0
- package/test/unary.ts +53 -0
- package/test/variable.ts +37 -0
- package/tests/Bitcode/BitcodeWriter.spec.ts +26 -0
- package/tests/Config/llvm-config.spec.ts +13 -0
- package/tests/IR/LLVMContext.spec.ts +8 -0
- package/tests/IR/Module.spec.ts +362 -0
- package/tests/IR/__snapshots__/Module.spec.ts.snap +11 -0
- package/tests/Support/TargetRegistry.spec.ts +38 -0
- package/tests/Support/TargetSelect.spec.ts +19 -0
- package/tests/Target/TargetMachine.spec.ts +19 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug Report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: "[Bug]"
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Your environment**
|
|
11
|
+
- OS version:
|
|
12
|
+
- Node.js version:
|
|
13
|
+
- LLVM version:
|
|
14
|
+
|
|
15
|
+
**Describe the bug**
|
|
16
|
+
|
|
17
|
+
A clear and concise description of what the bug is.
|
|
18
|
+
|
|
19
|
+
**Expected behavior**
|
|
20
|
+
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- '**'
|
|
7
|
+
paths-ignore:
|
|
8
|
+
- '*.md'
|
|
9
|
+
- 'LICENSE'
|
|
10
|
+
pull_request:
|
|
11
|
+
branches:
|
|
12
|
+
- '**'
|
|
13
|
+
paths-ignore:
|
|
14
|
+
- '*.md'
|
|
15
|
+
- 'LICENSE'
|
|
16
|
+
|
|
17
|
+
env:
|
|
18
|
+
LLVM_VERSION: 14.0.6
|
|
19
|
+
LLVM_VERSION_MAJOR: 14
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
build-push:
|
|
23
|
+
if: github.event_name == 'push'
|
|
24
|
+
name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
|
|
25
|
+
runs-on: ${{ matrix.os }}
|
|
26
|
+
strategy:
|
|
27
|
+
matrix:
|
|
28
|
+
os: [ macos-26, ubuntu-24.04, windows-2022 ]
|
|
29
|
+
node: [ 22 ]
|
|
30
|
+
steps:
|
|
31
|
+
- name: Fetch Codebase
|
|
32
|
+
uses: actions/checkout@v4
|
|
33
|
+
- name: Setup Node.js
|
|
34
|
+
uses: actions/setup-node@v3
|
|
35
|
+
with:
|
|
36
|
+
node-version: ${{ matrix.node }}
|
|
37
|
+
check-latest: true
|
|
38
|
+
- name: Install LLVM and Ninja on macOS
|
|
39
|
+
if: startsWith(matrix.os, 'macos')
|
|
40
|
+
run: |
|
|
41
|
+
brew update
|
|
42
|
+
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
|
|
43
|
+
- name: Install LLVM and Ninja on Ubuntu (via llvm.sh)
|
|
44
|
+
if: startsWith(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-24.04'
|
|
45
|
+
run: |
|
|
46
|
+
sudo wget https://apt.llvm.org/llvm.sh
|
|
47
|
+
sudo chmod +x llvm.sh
|
|
48
|
+
sudo ./llvm.sh ${{ env.LLVM_VERSION_MAJOR }}
|
|
49
|
+
sudo apt-get install ninja-build
|
|
50
|
+
- name: Install LLVM and Ninja on Ubuntu 24.04
|
|
51
|
+
if: matrix.os == 'ubuntu-24.04'
|
|
52
|
+
run: |
|
|
53
|
+
sudo apt-get update
|
|
54
|
+
sudo apt-get install -y llvm-${{ env.LLVM_VERSION_MAJOR }}-dev ninja-build
|
|
55
|
+
- name: Install LLVM on Windows
|
|
56
|
+
if: startsWith(matrix.os, 'windows')
|
|
57
|
+
run: |
|
|
58
|
+
$LLVM_VERSION = "${{ env.LLVM_VERSION }}"
|
|
59
|
+
$LLVM_PREBUILT_FILE = "llvm-$LLVM_VERSION-windows-2022.zip"
|
|
60
|
+
curl -sLO "https://github.com/DesignLiquido/llvm-windows/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PREBUILT_FILE"
|
|
61
|
+
Expand-Archive -Path $LLVM_PREBUILT_FILE -DestinationPath .
|
|
62
|
+
$LLVM_CMAKE_DIR = "$pwd/LLVM-$LLVM_VERSION-win64/lib/cmake/llvm"
|
|
63
|
+
if (-not (Test-Path $LLVM_CMAKE_DIR)) {
|
|
64
|
+
Write-Error "LLVM CMake directory not found: $LLVM_CMAKE_DIR"
|
|
65
|
+
exit 1
|
|
66
|
+
}
|
|
67
|
+
"LLVM_CMAKE_DIR=$LLVM_CMAKE_DIR" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
|
68
|
+
- name: Install Dependencies
|
|
69
|
+
run: npm install --ignore-scripts
|
|
70
|
+
- name: CMake Build Debug and Test
|
|
71
|
+
if: startsWith(matrix.os, 'windows') == false
|
|
72
|
+
run: |
|
|
73
|
+
npm run clear
|
|
74
|
+
npm run build:debug
|
|
75
|
+
npm test
|
|
76
|
+
- name: CMake Build Release and Test on Windows
|
|
77
|
+
if: startsWith(matrix.os, 'windows')
|
|
78
|
+
run: |
|
|
79
|
+
npm run clear
|
|
80
|
+
npx cmake-js print-configure "--CDLLVM_DIR=$env:LLVM_CMAKE_DIR" '--CDCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL'
|
|
81
|
+
npx cmake-js build "--CDLLVM_DIR=$env:LLVM_CMAKE_DIR" '--CDCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL'
|
|
82
|
+
npm test
|
|
83
|
+
- name: CMake Build Release and Test on non-Windows
|
|
84
|
+
if: startsWith(matrix.os, 'windows') == false
|
|
85
|
+
run: |
|
|
86
|
+
npm run clear
|
|
87
|
+
npm run build:release
|
|
88
|
+
npm test
|
|
89
|
+
|
|
90
|
+
build-pr:
|
|
91
|
+
if: github.event_name == 'pull_request'
|
|
92
|
+
name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
|
|
93
|
+
runs-on: ${{ matrix.os }}
|
|
94
|
+
strategy:
|
|
95
|
+
matrix:
|
|
96
|
+
os: [ macos-15, macos-15-intel, macos-26, ubuntu-22.04, ubuntu-24.04, windows-2022 ]
|
|
97
|
+
node: [ 18, 20, 22 ]
|
|
98
|
+
steps:
|
|
99
|
+
- name: Fetch Codebase
|
|
100
|
+
uses: actions/checkout@v4
|
|
101
|
+
- name: Setup Node.js
|
|
102
|
+
uses: actions/setup-node@v3
|
|
103
|
+
with:
|
|
104
|
+
node-version: ${{ matrix.node }}
|
|
105
|
+
check-latest: true
|
|
106
|
+
- name: Install LLVM and Ninja on macOS
|
|
107
|
+
if: startsWith(matrix.os, 'macos')
|
|
108
|
+
run: |
|
|
109
|
+
brew update
|
|
110
|
+
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
|
|
111
|
+
- name: Install LLVM and Ninja on Ubuntu (via llvm.sh)
|
|
112
|
+
if: startsWith(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-24.04'
|
|
113
|
+
run: |
|
|
114
|
+
sudo wget https://apt.llvm.org/llvm.sh
|
|
115
|
+
sudo chmod +x llvm.sh
|
|
116
|
+
sudo ./llvm.sh ${{ env.LLVM_VERSION_MAJOR }}
|
|
117
|
+
sudo apt-get install ninja-build
|
|
118
|
+
- name: Install LLVM and Ninja on Ubuntu 24.04
|
|
119
|
+
if: matrix.os == 'ubuntu-24.04'
|
|
120
|
+
run: |
|
|
121
|
+
sudo apt-get update
|
|
122
|
+
sudo apt-get install -y llvm-${{ env.LLVM_VERSION_MAJOR }}-dev ninja-build
|
|
123
|
+
- name: Install LLVM on Windows
|
|
124
|
+
if: startsWith(matrix.os, 'windows')
|
|
125
|
+
run: |
|
|
126
|
+
$LLVM_VERSION = "${{ env.LLVM_VERSION }}"
|
|
127
|
+
$LLVM_PREBUILT_FILE = "llvm-$LLVM_VERSION-windows-2022.zip"
|
|
128
|
+
curl -sLO "https://github.com/DesignLiquido/llvm-windows/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PREBUILT_FILE"
|
|
129
|
+
Expand-Archive -Path $LLVM_PREBUILT_FILE -DestinationPath .
|
|
130
|
+
$LLVM_CMAKE_DIR = "$pwd/LLVM-$LLVM_VERSION-win64/lib/cmake/llvm"
|
|
131
|
+
if (-not (Test-Path $LLVM_CMAKE_DIR)) {
|
|
132
|
+
Write-Error "LLVM CMake directory not found: $LLVM_CMAKE_DIR"
|
|
133
|
+
exit 1
|
|
134
|
+
}
|
|
135
|
+
"LLVM_CMAKE_DIR=$LLVM_CMAKE_DIR" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
|
136
|
+
- name: Install Dependencies
|
|
137
|
+
run: npm install --ignore-scripts
|
|
138
|
+
- name: CMake Build Debug and Test
|
|
139
|
+
if: startsWith(matrix.os, 'windows') == false
|
|
140
|
+
run: |
|
|
141
|
+
npm run clear
|
|
142
|
+
npm run build:debug
|
|
143
|
+
npm test
|
|
144
|
+
- name: CMake Build Release and Test on Windows
|
|
145
|
+
if: startsWith(matrix.os, 'windows')
|
|
146
|
+
run: |
|
|
147
|
+
npm run clear
|
|
148
|
+
npx cmake-js print-configure "--CDLLVM_DIR=$env:LLVM_CMAKE_DIR" '--CDCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL'
|
|
149
|
+
npx cmake-js build "--CDLLVM_DIR=$env:LLVM_CMAKE_DIR" '--CDCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL'
|
|
150
|
+
npm test
|
|
151
|
+
- name: CMake Build Release and Test on non-Windows
|
|
152
|
+
if: startsWith(matrix.os, 'windows') == false
|
|
153
|
+
run: |
|
|
154
|
+
npm run clear
|
|
155
|
+
npm run build:release
|
|
156
|
+
npm test
|
package/.release-it.json
ADDED
package/CHANGELOG.md
ADDED
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.17)
|
|
2
|
+
|
|
3
|
+
project(llvm-bindings)
|
|
4
|
+
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
|
|
7
|
+
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
|
8
|
+
|
|
9
|
+
include(CMakeJS)
|
|
10
|
+
|
|
11
|
+
include(LLVM)
|
|
12
|
+
|
|
13
|
+
include_directories(${CMAKE_JS_INC} include)
|
|
14
|
+
|
|
15
|
+
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
|
|
16
|
+
|
|
17
|
+
add_library(${PROJECT_NAME} SHARED ${CMAKE_JS_SRC} ${SOURCE_FILES})
|
|
18
|
+
|
|
19
|
+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node" LINKER_LANGUAGE CXX)
|
|
20
|
+
|
|
21
|
+
if (MSVC)
|
|
22
|
+
# cmake-js forces /MT (MultiThreaded static CRT), but LLVM 14 prebuilt Windows
|
|
23
|
+
# libraries were compiled with /MD (MultiThreadedDLL dynamic CRT). Override
|
|
24
|
+
# per-target so the linker can resolve __imp_strdup, __imp_read, etc. from ucrtbase.dll.
|
|
25
|
+
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
|
26
|
+
endif ()
|
|
27
|
+
|
|
28
|
+
execute_process(
|
|
29
|
+
COMMAND node -p "require('node-addon-api').include"
|
|
30
|
+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
31
|
+
OUTPUT_VARIABLE NODE_ADDON_API_DIR
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
string(REGEX REPLACE "[\r\n\"]" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
|
|
35
|
+
|
|
36
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} ${NODE_ADDON_API_DIR})
|
|
37
|
+
|
|
38
|
+
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${LLVM_LIBS})
|
|
39
|
+
|
|
40
|
+
add_definitions(-DNAPI_VERSION=8)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
pyyzcwg2833@outlook.com.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Contributing to llvm-bindings
|
|
2
|
+
|
|
3
|
+
## 1. Did you find a bug?
|
|
4
|
+
|
|
5
|
+
If you are willing to help fix this bug, please submit a pull request.
|
|
6
|
+
|
|
7
|
+
Otherwise, please go to the [issue page](https://github.com/ApsarasX/llvm-bindings/issues/new?template=bug_report.md&title=%5BBug%5D) to create an issue and describe the problem you encountered.
|
|
8
|
+
|
|
9
|
+
## 2. Do you need an API that llvm-bindings does not yet support?
|
|
10
|
+
|
|
11
|
+
If you are willing to help add new APIs, please submit a pull request.
|
|
12
|
+
|
|
13
|
+
Otherwise, please go to the [issue page](https://github.com/ApsarasX/llvm-bindings/issues/new?template=feature_request.md&title=%5BFeature%5D) to create an issue and list which LLVM APIs you need.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 ApsarasX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# llvm-bindings
|
|
2
|
+
|
|
3
|
+
LLVM bindings for Node.js/JavaScript/TypeScript. This project is a hard fork of https://github.com/ApsarasX/llvm-bindings, which it does not seem to be maintained anymore.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/DesignLiquido/llvm-bindings/actions)
|
|
6
|
+
[](https://www.npmjs.com/package/@designliquido/llvm-bindings)
|
|
7
|
+
[](https://github.com/DesignLiquido/llvm-bindings/blob/master/LICENSE)
|
|
8
|
+
|
|
9
|
+
## Supported OS
|
|
10
|
+
|
|
11
|
+
| | x86_64 | ARM64 |
|
|
12
|
+
|:------------------:|:------:|:-----:|
|
|
13
|
+
| macOS 15 Sequoia | ✅ | ✅ |
|
|
14
|
+
| macOS 26 | / | ✅ |
|
|
15
|
+
| Ubuntu 22.04 | ✅ | / |
|
|
16
|
+
| Ubuntu 24.04 | ✅ | / |
|
|
17
|
+
| Windows Server 2022| ✅ | ⚠️ |
|
|
18
|
+
|
|
19
|
+
> ⚠️ means not tested.
|
|
20
|
+
|
|
21
|
+
## Supported LLVM methods
|
|
22
|
+
|
|
23
|
+
listed in the [TypeScript definition file](./llvm-bindings.d.ts).
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
### Install on macOS
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
# install cmake and llvm by homebrew
|
|
31
|
+
brew install cmake llvm@14
|
|
32
|
+
|
|
33
|
+
# install llvm-bindings by yarn
|
|
34
|
+
yarn add llvm-bindings
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Install on Ubuntu
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
#install llvm by installation script
|
|
41
|
+
wget https://apt.llvm.org/llvm.sh
|
|
42
|
+
sudo chmod +x llvm.sh
|
|
43
|
+
sudo ./llvm.sh 14
|
|
44
|
+
|
|
45
|
+
# install cmake and zlib by apt-get
|
|
46
|
+
sudo apt-get install cmake zlib1g-dev
|
|
47
|
+
|
|
48
|
+
# install llvm-bindings by yarn
|
|
49
|
+
yarn add llvm-bindings
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Install on Windows
|
|
53
|
+
|
|
54
|
+
First, please refer to [Build LLVM from sources on Windows 10](https://github.com/ApsarasX/llvm-bindings/wiki/Build-LLVM-from-source-code-on-Windows-10) to build LLVM. An alternative is to download [prebuilt LLVM binary](https://github.com/ApsarasX/llvm-windows/releases).
|
|
55
|
+
|
|
56
|
+
Then, find the `llvm-config` command in your LLVM build directory and execute `llvm-config --cmakedir` to get LLVM cmake directory, assuming `C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm`.
|
|
57
|
+
|
|
58
|
+
Finally, execute the following commands.
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
# specify the LLVM cmake directory for cmake-js
|
|
62
|
+
# note: cmake-js reads npm-style config keys
|
|
63
|
+
npm config set cmake_LLVM_DIR C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm
|
|
64
|
+
|
|
65
|
+
# install llvm-bindings by yarn
|
|
66
|
+
yarn add llvm-bindings
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> Note: The build type of `llvm-bindings` must be consistent with LLVM, otherwise there will be many compilation errors when building `llvm-bindings`.
|
|
70
|
+
|
|
71
|
+
### Custom LLVM Installation
|
|
72
|
+
You can use the configuration options read by `cmake-js` to set the path to the LLVM cmake directory. This is needed if you don't want to use the system default LLVM installation.
|
|
73
|
+
|
|
74
|
+
```shell
|
|
75
|
+
# specify the llvm cmake directory by npm-compatible config and cmake-js
|
|
76
|
+
npm config set cmake_LLVM_DIR $(path-to-llvm/bin/llvm-config --cmakedir)
|
|
77
|
+
|
|
78
|
+
# install llvm-bindings by yarn
|
|
79
|
+
yarn add llvm-bindings
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
import llvm from 'llvm-bindings';
|
|
86
|
+
|
|
87
|
+
function main(): void {
|
|
88
|
+
const context = new llvm.LLVMContext();
|
|
89
|
+
const module = new llvm.Module('demo', context);
|
|
90
|
+
const builder = new llvm.IRBuilder(context);
|
|
91
|
+
|
|
92
|
+
const returnType = builder.getInt32Ty();
|
|
93
|
+
const paramTypes = [builder.getInt32Ty(), builder.getInt32Ty()];
|
|
94
|
+
const functionType = llvm.FunctionType.get(returnType, paramTypes, false);
|
|
95
|
+
const func = llvm.Function.Create(functionType, llvm.Function.LinkageTypes.ExternalLinkage, 'add', module);
|
|
96
|
+
|
|
97
|
+
const entryBB = llvm.BasicBlock.Create(context, 'entry', func);
|
|
98
|
+
builder.SetInsertPoint(entryBB);
|
|
99
|
+
const a = func.getArg(0);
|
|
100
|
+
const b = func.getArg(1);
|
|
101
|
+
const result = builder.CreateAdd(a, b);
|
|
102
|
+
builder.CreateRet(result);
|
|
103
|
+
|
|
104
|
+
if (llvm.verifyFunction(func)) {
|
|
105
|
+
console.error('Verifying function failed');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (llvm.verifyModule(module)) {
|
|
109
|
+
console.error('Verifying module failed');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(module.print());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
main();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
> You cannot declare a variable or constant named `module` in top level, because `module` is a built-in object in Node.js.
|
|
119
|
+
|
|
120
|
+
## Note
|
|
121
|
+
Due to the limitation of `node-addon-api`, this project has not implemented inheritance yet, so calling the method of superclass from subclass object will report an error. Please see [#1](https://github.com/ApsarasX/llvm-bindings/issues/1) for details.
|
|
122
|
+
|
|
123
|
+
## Compatibility
|
|
124
|
+
|
|
125
|
+
| llvm-bindings versions | compatible LLVM versions |
|
|
126
|
+
|------------------------|--------------------------|
|
|
127
|
+
| 0.0.x, 0.1.x | 11.0.x, 11.1.x |
|
|
128
|
+
| 0.2.x | 12.0.x |
|
|
129
|
+
| 0.3.x | 13.0.x |
|
|
130
|
+
| 0.4.x | 14.0.x |
|
|
131
|
+
|
|
132
|
+
## Acknowledgments
|
|
133
|
+
|
|
134
|
+
- [MichaReiser](https://github.com/MichaReiser): the creator of [llvm-node](https://github.com/MichaReiser/llvm-node)
|
|
135
|
+
- [ApsarasX's original `llvm-bindings` project](https://github.com/ApsarasX/llvm-bindings)
|
|
136
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
if (CMAKE_HOST_WIN32)
|
|
2
|
+
find_program(CMakeJS "cmake-js.cmd")
|
|
3
|
+
find_program(NPM "npm.cmd")
|
|
4
|
+
else ()
|
|
5
|
+
find_program(CMakeJS "cmake-js")
|
|
6
|
+
find_program(NPM "npm")
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
if (NPM)
|
|
10
|
+
message(STATUS "Found NPM")
|
|
11
|
+
else ()
|
|
12
|
+
message(FATAL_ERROR "NPM not found. This project requires Node.js.")
|
|
13
|
+
endif ()
|
|
14
|
+
|
|
15
|
+
if (CMakeJS)
|
|
16
|
+
message(STATUS "Found CMake.js")
|
|
17
|
+
else ()
|
|
18
|
+
message(FATAL_ERROR "CMake.js not found. This project requires cmake-js installed globally.")
|
|
19
|
+
endif ()
|
|
20
|
+
|
|
21
|
+
function(GET_VARIABLE INPUT_STRING VARIABLE_TO_SELECT OUTPUT_VARIABLE)
|
|
22
|
+
set(SEARCH_STRING "-D${VARIABLE_TO_SELECT}=")
|
|
23
|
+
string(LENGTH ${SEARCH_STRING} SEARCH_STRING_LENGTH)
|
|
24
|
+
string(LENGTH ${INPUT_STRING} INPUT_STRING_LENGTH)
|
|
25
|
+
string(FIND ${INPUT_STRING} ${SEARCH_STRING} SEARCH_STRING_INDEX)
|
|
26
|
+
if (${SEARCH_STRING_INDEX} LESS 0)
|
|
27
|
+
set(${OUTPUT_VARIABLE} "" PARENT_SCOPE)
|
|
28
|
+
else ()
|
|
29
|
+
math(EXPR SEARCH_STRING_INDEX "${SEARCH_STRING_INDEX}+${SEARCH_STRING_LENGTH}")
|
|
30
|
+
string(SUBSTRING ${INPUT_STRING} ${SEARCH_STRING_INDEX} ${INPUT_STRING_LENGTH} AFTER_SEARCH_STRING)
|
|
31
|
+
string(FIND ${AFTER_SEARCH_STRING} "'" QUOTE_INDEX)
|
|
32
|
+
string(SUBSTRING ${AFTER_SEARCH_STRING} 0 ${QUOTE_INDEX} RESULT_STRING)
|
|
33
|
+
set(${OUTPUT_VARIABLE} ${RESULT_STRING} PARENT_SCOPE)
|
|
34
|
+
endif ()
|
|
35
|
+
endfunction(GET_VARIABLE)
|
|
36
|
+
|
|
37
|
+
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
|
|
38
|
+
|
|
39
|
+
if (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
|
40
|
+
exec_program(
|
|
41
|
+
${CMakeJS}
|
|
42
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
43
|
+
ARGS print-configure --debug
|
|
44
|
+
OUTPUT_VARIABLE CMAKE_JS_OUTPUT
|
|
45
|
+
)
|
|
46
|
+
else ()
|
|
47
|
+
exec_program(
|
|
48
|
+
${CMakeJS}
|
|
49
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
50
|
+
ARGS print-configure
|
|
51
|
+
OUTPUT_VARIABLE CMAKE_JS_OUTPUT
|
|
52
|
+
)
|
|
53
|
+
endif ()
|
|
54
|
+
|
|
55
|
+
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_INC" CMAKE_JS_INC)
|
|
56
|
+
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_LIB" CMAKE_JS_LIB)
|
|
57
|
+
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_SRC" CMAKE_JS_SRC)
|
package/cmake/LLVM.cmake
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
if (CMAKE_HOST_APPLE)
|
|
2
|
+
file(GLOB LLVM_DIRS_INTEL /usr/local/opt/llvm*)
|
|
3
|
+
file(GLOB LLVM_DIRS_ARM /opt/homebrew/opt/llvm*)
|
|
4
|
+
list(APPEND LLVM_DIRS ${LLVM_DIRS_INTEL} ${LLVM_DIRS_ARM})
|
|
5
|
+
foreach (LLVM_DIR ${LLVM_DIRS})
|
|
6
|
+
list(APPEND CMAKE_PREFIX_PATH ${LLVM_DIR}/lib/cmake/llvm)
|
|
7
|
+
endforeach ()
|
|
8
|
+
endif ()
|
|
9
|
+
|
|
10
|
+
find_package(LLVM 14 REQUIRED CONFIG)
|
|
11
|
+
|
|
12
|
+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
|
13
|
+
|
|
14
|
+
include_directories(${LLVM_INCLUDE_DIRS})
|
|
15
|
+
|
|
16
|
+
add_definitions(${LLVM_DEFINITIONS})
|
|
17
|
+
|
|
18
|
+
llvm_map_components_to_libnames(LLVM_LIBS core codegen irreader linker support target ${LLVM_TARGETS_TO_BUILD})
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <napi.h>
|
|
4
|
+
#include <llvm/ADT/APFloat.h>
|
|
5
|
+
|
|
6
|
+
class APFloat : public Napi::ObjectWrap<APFloat> {
|
|
7
|
+
public:
|
|
8
|
+
static inline Napi::FunctionReference constructor; // NOLINT;
|
|
9
|
+
|
|
10
|
+
static void Init(Napi::Env env, Napi::Object &exports);
|
|
11
|
+
|
|
12
|
+
static bool IsClassOf(const Napi::Value &value);
|
|
13
|
+
|
|
14
|
+
static llvm::APFloat &Extract(const Napi::Value &value);
|
|
15
|
+
|
|
16
|
+
explicit APFloat(const Napi::CallbackInfo &info);
|
|
17
|
+
|
|
18
|
+
llvm::APFloat &getLLVMPrimitive();
|
|
19
|
+
|
|
20
|
+
private:
|
|
21
|
+
llvm::APFloat *apFloat = nullptr;
|
|
22
|
+
};
|