Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ApsarasX/llvm-bindings
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: TypeFox/llvm-bindings
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 19 files changed
  • 2 contributors

Commits on Apr 17, 2024

  1. Implement createArrayType (#1)

    * Implement createArrayType
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    
    * Add llvm-bindings.d.ts
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    
    ---------
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    gfontorbe authored Apr 17, 2024
    Copy the full SHA
    a66b57b View commit details

Commits on May 15, 2024

  1. Implement createStructType (#2)

    * Implement createArrayType
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    
    * Add llvm-bindings.d.ts
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    
    * implement createStructType
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    
    ---------
    
    Signed-off-by: Guillaume Fontorbe <guillaume.fontorbe@typefox.io>
    gfontorbe authored May 15, 2024
    Copy the full SHA
    701f6b6 View commit details

Commits on Jun 28, 2024

  1. cmake/CMakeJS.cmake: bug fix and improvements/optimizations

    * fixed bug in string splitting logic because of unexpected ';' that may occur within strings, and which confuse cmake
     -> no crash in case npm package 'NAN' is found in './node_modules' and included in addition to the headers of 'Node-API' (the new default native Node.js add-on API)
    * some optimizations targeting the cases of the variables to be assigned being already assigned
    sailingKieler committed Jun 28, 2024
    Copy the full SHA
    6a2d7c9 View commit details

Commits on Jul 8, 2024

  1. added missing implementations of 'isArrayTy', 'isIntegerTy', 'isPoint…

    …erTy', 'isStruct', 'isVectorTy' in DerivedTypes{.h,.cpp}, added missing declarations in 'llvm-bindings.d.ts'
    sailingKieler committed Jul 8, 2024
    Copy the full SHA
    221ffe9 View commit details
  2. Copy the full SHA
    239d6a8 View commit details
  3. Copy the full SHA
    4ea6cdc View commit details
  4. Copy the full SHA
    ceb4701 View commit details
  5. Copy the full SHA
    33f04a5 View commit details
  6. added some addition getters to 'IntegerType', 'FunctionType', and 'Ve…

    …ctorType', mainly for having them in the typescript definition
    
    * without these some of Typescript type definitions result in identical types and Typescripts type dispatch via the type guards doesn't work as expected
    sailingKieler committed Jul 8, 2024
    Copy the full SHA
    6565fa0 View commit details
  7. Copy the full SHA
    a8669e4 View commit details
  8. Added method 'getTypeAllocSizeInBits' to class 'DataLayout', added ad…

    …ditional constructor allowing to instantiate 'DataLayout' based on the existing 'Module'
    
    added corresponding tests
    sailingKieler committed Jul 8, 2024
    Copy the full SHA
    0b39e35 View commit details
  9. Copy the full SHA
    2993d11 View commit details
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -28,16 +28,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-10.15, macos-11, macos-12, ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022 ]
node: [ 14, 16, 18 ]
exclude:
- os: ubuntu-18.04
node: 18
os: [ macos-12, macos-13, macos-14, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022 ] # ubuntu-24.04 does not bring LLVM 14
node: [ 18, 20, 22 ]
steps:
- name: Fetch Codebase
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
check-latest: true
@@ -46,6 +43,7 @@ jobs:
run: |
brew update
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
echo "cmake_LLVM_DIR=$($(brew --prefix llvm@${{ env.LLVM_VERSION_MAJOR }})/bin/llvm-config --cmakedir)" > .npmrc
- name: Install LLVM and Ninja on Ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: |
@@ -61,7 +59,7 @@ jobs:
curl -sLO https://github.com/ApsarasX/llvm-windows/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PREBUILT_FILE
Expand-Archive -Path $LLVM_PREBUILT_FILE -DestinationPath .
$LLVM_CMAKE_DIR = "$pwd\\LLVM-$LLVM_VERSION-win64\\lib\\cmake\\llvm"
npm config set cmake_LLVM_DIR $LLVM_CMAKE_DIR
echo "cmake_LLVM_DIR=$LLVM_CMAKE_DIR"> .npmrc
- name: Install Dependencies
run: npm install --ignore-scripts
- name: CMake Build Debug and Test
@@ -74,4 +72,4 @@ jobs:
run: |
npm run clear
npm run build:release
npm test
npm test
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.npmrc

.idea/
.vscode/
.vscode/*
!.vscode/launch.json
!.vscode/settings.json

cmake-build-*/

@@ -14,4 +18,7 @@ package-lock.json
test/temp/

/**/**/.DS_Store
cmake_install.cmake
cmake_install.cmake

.cache/
CMakeFiles/
1 change: 1 addition & 0 deletions .npmrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake_LLVM_DIR=/opt/homebrew/opt/llvm@14/lib/cmake/llvm/
56 changes: 56 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Jest: Run tests in current file",
"type": "node",
"request": "launch",
"runtimeExecutable": "npx",
"program": "jest",
"args": [
"${relativeFile}",
],
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
"outFiles": [
"${workspaceFolder}/**/*.js"
]
},
{
"name": "Vitest: Run tests in current file",
"type": "node",
"request": "launch",
"runtimeExecutable": "npx",
"program": "vitest",
"args": [
"run",
"${relativeFile}",
],
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
"outFiles": [
"${workspaceFolder}/**/*.js"
]
},
{
/* execute npm build:debug before running this! */
"name": "LLDB: Debug LLVM-binding native parts during Vitest execution",
"type": "lldb",
"request": "launch",
"program": "node",
"sourceLanguages": ["cpp", "javascript"],
"args": [
"${workspaceFolder}/node_modules/vitest/dist/cli-wrapper.js",
"run",
"${relativeFile}",
],
},
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"C_Cpp.default.cStandard": "c17",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.includePath": [
"/opt/homebrew/opt/llvm@14/include",
"${userHome}/.cmake-js/node-*/v*/include/node",
"${workspaceFolder}/node_modules/node-addon-api",
"${workspaceFolder}/include",
],
"clangd.fallbackFlags": [
"-std=c++17",
"-xc++-header",
"-I/opt/homebrew/opt/llvm@14/include",
"-I${userHome}/.cmake-js/node-arm64/v18.18.2/include/node/", /* switch to your arch & version here! */
"-I${workspaceFolder}/node_modules/node-addon-api",
"-I${workspaceFolder}/include",
]
}
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -29,9 +29,21 @@ listed in the [TypeScript definition file](./llvm-bindings.d.ts).

### Install on macOS

Make sure `llvm@14` as well as `cmake` are available, e.g. via
```shell
# install cmake and llvm by homebrew
brew install cmake llvm@14
```

Tell the extra build tool used here (`cmake-js`) where to find some cmake-specific integration setup of LLVM 14, then `npm install` the package.
1. First create the required new file named `.npmrc`
* alternatively, copy `.npmrc.template` to `.npmrc` and adapt the configured path if needed, `brew --prefix llvm@14` gives you the install dir of LLVM14.
2. Then run `npm install llvm-bindings`

```shell
# specify the LLVM cmake directory for cmake-js
# also see '.npmrc.template' for reference
echo "cmake_LLVM_DIR=$($(brew --prefix llvm@14)/bin/llvm-config --cmakedir)" > .npmrc

# install llvm-bindings by npm
npm install llvm-bindings
@@ -54,15 +66,18 @@ npm install llvm-bindings

### Install on Windows

_Update:_ Use LLVM in version `14.0.6` sequently.

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).

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`.
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-14.0.6.src\build\lib\cmake\llvm`.

Finally, execute the following commands.

```shell
# specify the LLVM cmake directory for cmake-js
npm config set cmake_LLVM_DIR C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm
# also see '.npmrc.template' for reference
echo "cmake_LLVM_DIR=C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm" > .npmrc

# install llvm-bindings by npm
npm install llvm-bindings
@@ -72,10 +87,14 @@ npm install llvm-bindings
### Custom LLVM Installation
You can use the npm configuration options to set the path to the LLVM cmake directory. This is needed if you don't want to use the system default LLVM installation.
(Formerly, `npm config` was used here. Meanwhile npm validates the config keys for being known and valid, and rejects custom keys.)


```shell
# specify the llvm cmake directory by npm and cmake-js
npm config set cmake_LLVM_DIR $(path-to-llvm/bin/llvm-config --cmakedir)
# also see '.npmrc.template' for reference
# on macos `path-to-llvm` can be obtained via `brew --prefix llvm@14`
echo "cmake_LLVM_DIR=$(path-to-llvm/bin/llvm-config --cmakedir)" > .npmrc

# install llvm-bindings by npm
npm install llvm-bindings
55 changes: 41 additions & 14 deletions cmake/CMakeJS.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# the aim of this script is to ensure the definition of the following variables,
# which are referenced by the root script in '../CMakeLists.txt';
# be aware that cmake caches the assignments of properties, here in './build/CMakeCache.txt',
# once set those assignments don't need to be repeated in consecutive calls of 'cmake';

# consequently, in order to prevent potentially unexpected re-assignments by this script:
if ((DEFINED CMAKE_JS_SRC) AND (DEFINED CMAKE_JS_INC) AND (DEFINED CMAKE_JS_LIB))
message(STATUS "Early returning from CMakeJS.cmake, as CMAKE_JS_SRC, CMAKE_JS_INC and CMAKE_JS_LIB are already defined.")
return()
endif()

if (CMAKE_HOST_WIN32)
find_program(CMakeJS "cmake-js.cmd")
find_program(NPM "npm.cmd")
@@ -28,30 +39,46 @@ function(GET_VARIABLE INPUT_STRING VARIABLE_TO_SELECT OUTPUT_VARIABLE)
else ()
math(EXPR SEARCH_STRING_INDEX "${SEARCH_STRING_INDEX}+${SEARCH_STRING_LENGTH}")
string(SUBSTRING ${INPUT_STRING} ${SEARCH_STRING_INDEX} ${INPUT_STRING_LENGTH} AFTER_SEARCH_STRING)
string(FIND ${AFTER_SEARCH_STRING} "'" QUOTE_INDEX)
string(SUBSTRING ${AFTER_SEARCH_STRING} 0 ${QUOTE_INDEX} RESULT_STRING)
set(${OUTPUT_VARIABLE} ${RESULT_STRING} PARENT_SCOPE)
# here, ${AFTER_SEARCH_STRING} may be a string of ';'-separated substrings being composed by cmake.js, see cmake-js/lib/cMake.js, line 140ff.;
# after expanding cmake treats that string as a list of values, which are then assigned to the arguments of 'FIND',
# which will break the call of 'FIND' because of an argument number mismatch -> wrap ${AFTER_SEARCH_STRING} with "" !
string(FIND "${AFTER_SEARCH_STRING}" "'" QUOTE_INDEX)
string(SUBSTRING "${AFTER_SEARCH_STRING}" 0 ${QUOTE_INDEX} RESULT_STRING)
set(${OUTPUT_VARIABLE} "${RESULT_STRING}" PARENT_SCOPE)
endif ()
endfunction(GET_VARIABLE)

# just to be explicit:
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "release")
endif()

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 ()

get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_INC" CMAKE_JS_INC)
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_LIB" CMAKE_JS_LIB)
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_SRC" CMAKE_JS_SRC)
# only write the following variables if and only if they haven't been already determined by the caller,
# specifically, don't overwrite them!
if (NOT CMAKE_JS_INC)
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_INC" CMAKE_JS_INC)
endif()

if (NOT CMAKE_JS_LIB)
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_LIB" CMAKE_JS_LIB)
endif()

if (NOT CMAKE_JS_SRC)
get_variable(${CMAKE_JS_OUTPUT} "CMAKE_JS_SRC" CMAKE_JS_SRC)
endif()
4 changes: 4 additions & 0 deletions include/IR/DIBuilder.h
Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@ class DIBuilder : public Napi::ObjectWrap<DIBuilder> {

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

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

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

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

Napi::Value createSubroutineType(const Napi::CallbackInfo &info);
2 changes: 2 additions & 0 deletions include/IR/DataLayout.h
Original file line number Diff line number Diff line change
@@ -25,4 +25,6 @@ class DataLayout : public Napi::ObjectWrap<DataLayout> {
Napi::Value getStringRepresentation(const Napi::CallbackInfo &info);

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

Napi::Value getTypeAllocSizeInBits(const Napi::CallbackInfo &info);
};
Loading