@designliquido/llvm-bindings 0.1.0 → 2.0.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/workflows/build.yml +4 -4
- package/CHANGELOG.md +32 -1
- package/CMakeLists.txt +1 -1
- package/README.md +33 -11
- package/cmake/LLVM.cmake +1 -1
- package/include/IR/DerivedTypes.h +3 -1
- package/include/IR/IRBuilder.h +2 -0
- package/include/IR/Type.h +1 -1
- package/include/Util/ErrMsg.h +3 -2
- package/include/assert.h +13 -0
- package/llvm-bindings.d.ts +13 -11
- package/package.json +2 -2
- package/src/IR/Attributes.cpp +6 -82
- package/src/IR/DataLayout.cpp +1 -1
- package/src/IR/DerivedTypes.cpp +30 -9
- package/src/IR/Function.cpp +4 -2
- package/src/IR/IRBuilder.cpp +18 -6
- package/src/IR/Intrinsic.cpp +0 -1
- package/src/IR/Type.cpp +8 -8
- package/src/MC/TargetRegistry.cpp +2 -1
- package/src/llvm-bindings.cpp +25 -0
- package/test/exception.ts +1 -1
|
@@ -15,8 +15,8 @@ on:
|
|
|
15
15
|
- 'LICENSE'
|
|
16
16
|
|
|
17
17
|
env:
|
|
18
|
-
LLVM_VERSION:
|
|
19
|
-
LLVM_VERSION_MAJOR:
|
|
18
|
+
LLVM_VERSION: 16.0.6
|
|
19
|
+
LLVM_VERSION_MAJOR: 16
|
|
20
20
|
|
|
21
21
|
jobs:
|
|
22
22
|
build-push:
|
|
@@ -39,7 +39,7 @@ jobs:
|
|
|
39
39
|
if: startsWith(matrix.os, 'macos')
|
|
40
40
|
run: |
|
|
41
41
|
brew update
|
|
42
|
-
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
|
|
42
|
+
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja || brew link --overwrite python@3.12
|
|
43
43
|
- name: Install LLVM and Ninja on Ubuntu (via llvm.sh)
|
|
44
44
|
if: startsWith(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-24.04'
|
|
45
45
|
run: |
|
|
@@ -107,7 +107,7 @@ jobs:
|
|
|
107
107
|
if: startsWith(matrix.os, 'macos')
|
|
108
108
|
run: |
|
|
109
109
|
brew update
|
|
110
|
-
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
|
|
110
|
+
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja || brew link --overwrite python@3.12
|
|
111
111
|
- name: Install LLVM and Ninja on Ubuntu (via llvm.sh)
|
|
112
112
|
if: startsWith(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-24.04'
|
|
113
113
|
run: |
|
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
# [1.0.0](https://github.com/DesignLiquido/llvm-bindings/compare/v0.4.2...v1.0.0) (2026-03-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* uncomment test entry ([69c93f7](https://github.com/DesignLiquido/llvm-bindings/commit/69c93f7aae697c3cb3e75d01e447554b0565e3d5))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **Attribute:** add basic support for enum attributes ([#32](https://github.com/DesignLiquido/llvm-bindings/issues/32)) ([db45aa5](https://github.com/DesignLiquido/llvm-bindings/commit/db45aa583729956dfefa01772ab69f019e56b05a))
|
|
12
|
+
## [1.0.0] - 2026-03-07
|
|
2
13
|
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **Opaque pointer support (LLVM 15):** `PointerType.get` and `PointerType.getUnqual` now accept either a `Type` (typed pointer, existing behaviour) or an `LLVMContext` (opaque pointer, new in LLVM 15). No method renames — the overloads are resolved at runtime by inspecting the first argument.
|
|
17
|
+
- `PointerType.isOpaque()` — returns `true` when the pointer type carries no element type.
|
|
18
|
+
- `Type.isOpaquePointerTy()` — lets user code branch between typed- and opaque-pointer paths.
|
|
19
|
+
- `IRBuilder.getPtrTy(addrSpace?)` — returns the opaque `ptr` type; canonical replacement for `getInt8PtrTy()` in opaque-pointer IR.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `isSameType` (internal helper in `src/IR/Type.cpp`) no longer aborts when either pointer is opaque; it now guards the `getPointerElementType()` call and compares opaqueness directly.
|
|
24
|
+
|
|
25
|
+
### Notes
|
|
26
|
+
|
|
27
|
+
- Typed-pointer APIs are unchanged. The LLVM 15 compatibility shim (`context->setOpaquePointers(false)`) remains active by default, so existing code continues to work without modification.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## [0.1.0]
|
|
32
|
+
|
|
33
|
+
Initial release.
|
package/CMakeLists.txt
CHANGED
|
@@ -19,7 +19,7 @@ add_library(${PROJECT_NAME} SHARED ${CMAKE_JS_SRC} ${SOURCE_FILES})
|
|
|
19
19
|
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node" LINKER_LANGUAGE CXX)
|
|
20
20
|
|
|
21
21
|
if (MSVC)
|
|
22
|
-
# cmake-js forces /MT (MultiThreaded static CRT), but LLVM
|
|
22
|
+
# cmake-js forces /MT (MultiThreaded static CRT), but LLVM 15 prebuilt Windows
|
|
23
23
|
# libraries were compiled with /MD (MultiThreadedDLL dynamic CRT). Override
|
|
24
24
|
# per-target so the linker can resolve __imp_strdup, __imp_read, etc. from ucrtbase.dll.
|
|
25
25
|
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
[](https://github.com/DesignLiquido/llvm-bindings/actions)
|
|
6
6
|
[](https://www.npmjs.com/package/@designliquido/llvm-bindings)
|
|
7
7
|
[](https://github.com/DesignLiquido/llvm-bindings/blob/master/LICENSE)
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ listed in the [TypeScript definition file](./llvm-bindings.d.ts).
|
|
|
28
28
|
|
|
29
29
|
```shell
|
|
30
30
|
# install cmake and llvm by homebrew
|
|
31
|
-
brew install cmake llvm@
|
|
31
|
+
brew install cmake llvm@15
|
|
32
32
|
|
|
33
33
|
# install llvm-bindings by yarn
|
|
34
34
|
yarn add llvm-bindings
|
|
@@ -40,7 +40,7 @@ yarn add llvm-bindings
|
|
|
40
40
|
#install llvm by installation script
|
|
41
41
|
wget https://apt.llvm.org/llvm.sh
|
|
42
42
|
sudo chmod +x llvm.sh
|
|
43
|
-
sudo ./llvm.sh
|
|
43
|
+
sudo ./llvm.sh 15
|
|
44
44
|
|
|
45
45
|
# install cmake and zlib by apt-get
|
|
46
46
|
sudo apt-get install cmake zlib1g-dev
|
|
@@ -53,14 +53,14 @@ yarn add llvm-bindings
|
|
|
53
53
|
|
|
54
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
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-
|
|
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-15.0.7.src\build\lib\cmake\llvm`.
|
|
57
57
|
|
|
58
58
|
Finally, execute the following commands.
|
|
59
59
|
|
|
60
60
|
```shell
|
|
61
61
|
# specify the LLVM cmake directory for cmake-js
|
|
62
62
|
# note: cmake-js reads npm-style config keys
|
|
63
|
-
npm config set cmake_LLVM_DIR C:\Users\dev\llvm-
|
|
63
|
+
npm config set cmake_LLVM_DIR C:\Users\dev\llvm-15.0.7.src\build\lib\cmake\llvm
|
|
64
64
|
|
|
65
65
|
# install llvm-bindings by yarn
|
|
66
66
|
yarn add llvm-bindings
|
|
@@ -120,14 +120,36 @@ main();
|
|
|
120
120
|
## Note
|
|
121
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
122
|
|
|
123
|
+
## Opaque Pointers (LLVM 15 / v1.0.0)
|
|
124
|
+
|
|
125
|
+
LLVM 15 makes opaque pointers the default. Starting from v1.0.0 this library exposes the necessary APIs to opt into opaque-pointer IR while keeping all existing typed-pointer APIs intact.
|
|
126
|
+
|
|
127
|
+
**New APIs**
|
|
128
|
+
|
|
129
|
+
| API | Description |
|
|
130
|
+
|-----|-------------|
|
|
131
|
+
| `PointerType.get(context, addrSpace)` | Creates an opaque pointer type (pass `LLVMContext` instead of `Type`) |
|
|
132
|
+
| `PointerType.getUnqual(context)` | Shorthand for address space 0 opaque pointer |
|
|
133
|
+
| `PointerType.isOpaque()` | Returns `true` if the pointer type carries no element type |
|
|
134
|
+
| `Type.isOpaquePointerTy()` | Returns `true` if the type is an opaque pointer |
|
|
135
|
+
| `IRBuilder.getPtrTy(addrSpace?)` | Returns the opaque `ptr` type; replaces `getInt8PtrTy()` in opaque-pointer IR |
|
|
136
|
+
|
|
137
|
+
**Compatibility shim**
|
|
138
|
+
|
|
139
|
+
Typed-pointer code continues to work without changes. The compatibility flag `context->setOpaquePointers(false)` is set automatically in `LLVMContext`'s constructor, so existing code is unaffected.
|
|
140
|
+
|
|
141
|
+
To opt into opaque pointers, pass an `LLVMContext` to `PointerType.get` / `getUnqual` and use `getPtrTy()` for generic pointer values.
|
|
142
|
+
|
|
123
143
|
## Compatibility
|
|
124
144
|
|
|
125
|
-
| llvm-bindings versions
|
|
126
|
-
|
|
127
|
-
| 0.0.x, 0.1.x
|
|
128
|
-
| 0.2.x
|
|
129
|
-
| 0.3.x
|
|
130
|
-
| 0.4.x
|
|
145
|
+
| llvm-bindings versions | compatible LLVM versions |
|
|
146
|
+
|--------------------------------------------|--------------------------|
|
|
147
|
+
| (original llvm-bindings repo) 0.0.x, 0.1.x | 11.0.x, 11.1.x |
|
|
148
|
+
| (original llvm-bindings repo) 0.2.x | 12.0.x |
|
|
149
|
+
| (original llvm-bindings repo) 0.3.x | 13.0.x |
|
|
150
|
+
| (original llvm-bindings repo) 0.4.x | 14.0.x |
|
|
151
|
+
| (@designliquido/llvm-bindings) 0.1.x | 14.0.x |
|
|
152
|
+
| (@designliquido/llvm-bindings) 1.0.x | 15.0.x |
|
|
131
153
|
|
|
132
154
|
## Acknowledgments
|
|
133
155
|
|
package/cmake/LLVM.cmake
CHANGED
|
@@ -228,5 +228,7 @@ private:
|
|
|
228
228
|
|
|
229
229
|
Napi::Value getTypeID(const Napi::CallbackInfo &info);
|
|
230
230
|
|
|
231
|
-
Napi::Value
|
|
231
|
+
Napi::Value getNonOpaquePointerElementType(const Napi::CallbackInfo &info);
|
|
232
|
+
|
|
233
|
+
Napi::Value isOpaque(const Napi::CallbackInfo &info);
|
|
232
234
|
};
|
package/include/IR/IRBuilder.h
CHANGED
|
@@ -179,6 +179,8 @@ private:
|
|
|
179
179
|
|
|
180
180
|
Napi::Value getInt8PtrTy(const Napi::CallbackInfo &info);
|
|
181
181
|
|
|
182
|
+
Napi::Value getPtrTy(const Napi::CallbackInfo &info);
|
|
183
|
+
|
|
182
184
|
Napi::Value getIntPtrTy(const Napi::CallbackInfo &info);
|
|
183
185
|
|
|
184
186
|
//===--------------------------------------------------------------------===//
|
package/include/IR/Type.h
CHANGED
|
@@ -39,7 +39,7 @@ private:
|
|
|
39
39
|
return Napi::Boolean::New(info.Env(), (type->*method)());
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
Napi::Value
|
|
42
|
+
Napi::Value getNonOpaquePointerElementType(const Napi::CallbackInfo &info);
|
|
43
43
|
|
|
44
44
|
static Napi::Value isSameType(const Napi::CallbackInfo &info);
|
|
45
45
|
};
|
package/include/Util/ErrMsg.h
CHANGED
|
@@ -74,8 +74,8 @@ namespace ErrMsg {
|
|
|
74
74
|
}
|
|
75
75
|
namespace PointerType {
|
|
76
76
|
constexpr const char *constructor = "PointerType.constructor needs to be called with new (external: Napi::External<llvm::PointerType>)";
|
|
77
|
-
constexpr const char *get = "PointerType.get needs to be called with: (elementType: Type, addrSpace: number)";
|
|
78
|
-
constexpr const char *getUnqual = "PointerType.getUnqual needs to be called with: (elementType: Type)";
|
|
77
|
+
constexpr const char *get = "PointerType.get needs to be called with: (elementType: Type | context: LLVMContext, addrSpace: number)";
|
|
78
|
+
constexpr const char *getUnqual = "PointerType.getUnqual needs to be called with: (elementType: Type | context: LLVMContext)";
|
|
79
79
|
}
|
|
80
80
|
namespace Value {
|
|
81
81
|
constexpr const char *constructor = "Value.constructor needs to be called with new (external: Napi::External<llvm::Value>)";
|
|
@@ -406,6 +406,7 @@ namespace ErrMsg {
|
|
|
406
406
|
|
|
407
407
|
constexpr const char *getIntNTy = "IRBuilder.getIntNTy needs to be called with (numBits: number)";
|
|
408
408
|
constexpr const char *getInt8PtrTy = "IRBuilder.getInt8PtrTy needs to be called with (addrSpace?: number)";
|
|
409
|
+
constexpr const char *getPtrTy = "IRBuilder.getPtrTy needs to be called with (addrSpace?: number)";
|
|
409
410
|
constexpr const char *getIntPtrTy = "IRBuilder.getIntPtrTy needs to be called with (dataLayout: DataLayout, addrSpace?: number)";
|
|
410
411
|
|
|
411
412
|
constexpr const char *CreateRet = "IRBuilder.CreateRet needs to be called with: (value: Value)";
|
package/include/assert.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#ifndef LLVM_BINDINGS_NODEJS_ASSERT_H
|
|
2
|
+
#define LLVM_BINDINGS_NODEJS_ASSERT_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
void llvm_bindings_assert(const char* expr, const char* file, int line);
|
|
6
|
+
|
|
7
|
+
#define LLVM_BINDINGS_ASSERT_IMPL(e, file, line) ((void)llvm_bindings_assert ((e), (file), (line)))
|
|
8
|
+
|
|
9
|
+
#define assert(e) ((void) ((e) ? ((void)0) : LLVM_BINDINGS_ASSERT_IMPL (#e, __FILE__, __LINE__)))
|
|
10
|
+
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#endif
|
package/llvm-bindings.d.ts
CHANGED
|
@@ -247,7 +247,6 @@ declare namespace llvm {
|
|
|
247
247
|
VoidTyID: number;
|
|
248
248
|
LabelTyID: number;
|
|
249
249
|
MetadataTyID: number;
|
|
250
|
-
X86_MMXTyID: number;
|
|
251
250
|
TokenTyID: number;
|
|
252
251
|
IntegerTyID: number;
|
|
253
252
|
FunctionTyID: number;
|
|
@@ -278,8 +277,6 @@ declare namespace llvm {
|
|
|
278
277
|
|
|
279
278
|
public static getPPC_FP128Ty(context: LLVMContext): Type;
|
|
280
279
|
|
|
281
|
-
public static getX86_MMXTy(context: LLVMContext): Type;
|
|
282
|
-
|
|
283
280
|
public static getTokenTy(context: LLVMContext): Type;
|
|
284
281
|
|
|
285
282
|
public static getIntNTy(context: LLVMContext, numBits: number): IntegerType;
|
|
@@ -310,8 +307,6 @@ declare namespace llvm {
|
|
|
310
307
|
|
|
311
308
|
public static getPPC_FP128PtrTy(context: LLVMContext, addrSpace?: number): PointerType;
|
|
312
309
|
|
|
313
|
-
public static getX86_MMXPtrTy(context: LLVMContext, addrSpace?: number): PointerType;
|
|
314
|
-
|
|
315
310
|
public static getInt1PtrTy(context: LLVMContext, addrSpace?: number): PointerType;
|
|
316
311
|
|
|
317
312
|
public static getInt8PtrTy(context: LLVMContext, addrSpace?: number): PointerType;
|
|
@@ -342,8 +337,6 @@ declare namespace llvm {
|
|
|
342
337
|
|
|
343
338
|
public isFloatingPointTy(): boolean;
|
|
344
339
|
|
|
345
|
-
public isX86_MMXTy(): boolean;
|
|
346
|
-
|
|
347
340
|
public isLabelTy(): boolean;
|
|
348
341
|
|
|
349
342
|
public isMetadataTy(): boolean;
|
|
@@ -360,6 +353,8 @@ declare namespace llvm {
|
|
|
360
353
|
|
|
361
354
|
public isPointerTy(): boolean;
|
|
362
355
|
|
|
356
|
+
public isOpaquePointerTy(): boolean;
|
|
357
|
+
|
|
363
358
|
public isVectorTy(): boolean;
|
|
364
359
|
|
|
365
360
|
public isEmptyTy(): boolean;
|
|
@@ -374,7 +369,7 @@ declare namespace llvm {
|
|
|
374
369
|
|
|
375
370
|
public getPrimitiveSizeInBits(): number;
|
|
376
371
|
|
|
377
|
-
public
|
|
372
|
+
public getNonOpaquePointerElementType(): Type;
|
|
378
373
|
|
|
379
374
|
// extra
|
|
380
375
|
public static isSameType(type1: Type, type2: Type): boolean;
|
|
@@ -498,8 +493,10 @@ declare namespace llvm {
|
|
|
498
493
|
|
|
499
494
|
class PointerType extends Type {
|
|
500
495
|
public static get(elementType: Type, addrSpace: number): PointerType;
|
|
496
|
+
public static get(context: LLVMContext, addrSpace: number): PointerType;
|
|
501
497
|
|
|
502
498
|
public static getUnqual(elementType: Type): PointerType;
|
|
499
|
+
public static getUnqual(context: LLVMContext): PointerType;
|
|
503
500
|
|
|
504
501
|
// duplicated
|
|
505
502
|
public isPointerTy(): boolean;
|
|
@@ -516,8 +513,12 @@ declare namespace llvm {
|
|
|
516
513
|
// duplicated
|
|
517
514
|
public getTypeID(): number;
|
|
518
515
|
|
|
519
|
-
|
|
520
|
-
|
|
516
|
+
/**
|
|
517
|
+
* @deprecated In LLVM 15/16 this is deprecated. LLVM 17 removes it.
|
|
518
|
+
*/
|
|
519
|
+
public getNonOpaquePointerElementType(): Type;
|
|
520
|
+
|
|
521
|
+
public isOpaque(): boolean;
|
|
521
522
|
|
|
522
523
|
protected constructor();
|
|
523
524
|
}
|
|
@@ -1427,6 +1428,8 @@ declare namespace llvm {
|
|
|
1427
1428
|
|
|
1428
1429
|
public getInt8PtrTy(addrSpace?: number): PointerType;
|
|
1429
1430
|
|
|
1431
|
+
public getPtrTy(addrSpace?: number): PointerType;
|
|
1432
|
+
|
|
1430
1433
|
public getIntPtrTy(dataLayout: DataLayout, addrSpace?: number): IntegerType;
|
|
1431
1434
|
|
|
1432
1435
|
//===--------------------------------------------------------------------===//
|
|
@@ -1942,7 +1945,6 @@ declare namespace llvm {
|
|
|
1942
1945
|
const expect_with_probability: number;
|
|
1943
1946
|
const fabs: number;
|
|
1944
1947
|
const floor: number;
|
|
1945
|
-
const flt_rounds: number;
|
|
1946
1948
|
const fma: number;
|
|
1947
1949
|
const fmuladd: number;
|
|
1948
1950
|
const fptosi_sat: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designliquido/llvm-bindings",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "LLVM bindings for Node.js/JavaScript/TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llvm",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"publish": true
|
|
67
67
|
},
|
|
68
68
|
"hooks": {
|
|
69
|
-
"before:git:release": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
|
|
69
|
+
"before:git:release": "yarn conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/IR/Attributes.cpp
CHANGED
|
@@ -5,88 +5,12 @@ void Attribute::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
5
5
|
Napi::HandleScope scope(env);
|
|
6
6
|
|
|
7
7
|
Napi::Object attributeKinds = Napi::Object::New(env);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Napi::Number::New(env, llvm::Attribute::AttrKind::DisableSanitizerInstrumentation));
|
|
15
|
-
attributeKinds.Set("Hot", Napi::Number::New(env, llvm::Attribute::AttrKind::Hot));
|
|
16
|
-
attributeKinds.Set("ImmArg", Napi::Number::New(env, llvm::Attribute::AttrKind::ImmArg));
|
|
17
|
-
attributeKinds.Set("InReg", Napi::Number::New(env, llvm::Attribute::AttrKind::InReg));
|
|
18
|
-
attributeKinds.Set("InaccessibleMemOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::InaccessibleMemOnly));
|
|
19
|
-
attributeKinds.Set("InaccessibleMemOrArgMemOnly",
|
|
20
|
-
Napi::Number::New(env, llvm::Attribute::AttrKind::InaccessibleMemOrArgMemOnly));
|
|
21
|
-
attributeKinds.Set("InlineHint", Napi::Number::New(env, llvm::Attribute::AttrKind::InlineHint));
|
|
22
|
-
attributeKinds.Set("JumpTable", Napi::Number::New(env, llvm::Attribute::AttrKind::JumpTable));
|
|
23
|
-
attributeKinds.Set("MinSize", Napi::Number::New(env, llvm::Attribute::AttrKind::MinSize));
|
|
24
|
-
attributeKinds.Set("MustProgress", Napi::Number::New(env, llvm::Attribute::AttrKind::MustProgress));
|
|
25
|
-
attributeKinds.Set("Naked", Napi::Number::New(env, llvm::Attribute::AttrKind::Naked));
|
|
26
|
-
attributeKinds.Set("Nest", Napi::Number::New(env, llvm::Attribute::AttrKind::Nest));
|
|
27
|
-
attributeKinds.Set("NoAlias", Napi::Number::New(env, llvm::Attribute::AttrKind::NoAlias));
|
|
28
|
-
attributeKinds.Set("NoBuiltin", Napi::Number::New(env, llvm::Attribute::AttrKind::NoBuiltin));
|
|
29
|
-
attributeKinds.Set("NoCallback", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCallback));
|
|
30
|
-
attributeKinds.Set("NoCapture", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCapture));
|
|
31
|
-
attributeKinds.Set("NoCfCheck", Napi::Number::New(env, llvm::Attribute::AttrKind::NoCfCheck));
|
|
32
|
-
attributeKinds.Set("NoDuplicate", Napi::Number::New(env, llvm::Attribute::AttrKind::NoDuplicate));
|
|
33
|
-
attributeKinds.Set("NoFree", Napi::Number::New(env, llvm::Attribute::AttrKind::NoFree));
|
|
34
|
-
attributeKinds.Set("NoImplicitFloat", Napi::Number::New(env, llvm::Attribute::AttrKind::NoImplicitFloat));
|
|
35
|
-
attributeKinds.Set("NoInline", Napi::Number::New(env, llvm::Attribute::AttrKind::NoInline));
|
|
36
|
-
attributeKinds.Set("NoMerge", Napi::Number::New(env, llvm::Attribute::AttrKind::NoMerge));
|
|
37
|
-
attributeKinds.Set("NoProfile", Napi::Number::New(env, llvm::Attribute::AttrKind::NoProfile));
|
|
38
|
-
attributeKinds.Set("NoRecurse", Napi::Number::New(env, llvm::Attribute::AttrKind::NoRecurse));
|
|
39
|
-
attributeKinds.Set("NoRedZone", Napi::Number::New(env, llvm::Attribute::AttrKind::NoRedZone));
|
|
40
|
-
attributeKinds.Set("NoReturn", Napi::Number::New(env, llvm::Attribute::AttrKind::NoReturn));
|
|
41
|
-
attributeKinds.Set("NoSanitizeCoverage", Napi::Number::New(env, llvm::Attribute::AttrKind::NoSanitizeCoverage));
|
|
42
|
-
attributeKinds.Set("NoSync", Napi::Number::New(env, llvm::Attribute::AttrKind::NoSync));
|
|
43
|
-
attributeKinds.Set("NoUndef", Napi::Number::New(env, llvm::Attribute::AttrKind::NoUndef));
|
|
44
|
-
attributeKinds.Set("NoUnwind", Napi::Number::New(env, llvm::Attribute::AttrKind::NoUnwind));
|
|
45
|
-
attributeKinds.Set("NonLazyBind", Napi::Number::New(env, llvm::Attribute::AttrKind::NonLazyBind));
|
|
46
|
-
attributeKinds.Set("NonNull", Napi::Number::New(env, llvm::Attribute::AttrKind::NonNull));
|
|
47
|
-
attributeKinds.Set("NullPointerIsValid", Napi::Number::New(env, llvm::Attribute::AttrKind::NullPointerIsValid));
|
|
48
|
-
attributeKinds.Set("OptForFuzzing", Napi::Number::New(env, llvm::Attribute::AttrKind::OptForFuzzing));
|
|
49
|
-
attributeKinds.Set("OptimizeForSize", Napi::Number::New(env, llvm::Attribute::AttrKind::OptimizeForSize));
|
|
50
|
-
attributeKinds.Set("OptimizeNone", Napi::Number::New(env, llvm::Attribute::AttrKind::OptimizeNone));
|
|
51
|
-
attributeKinds.Set("ReadNone", Napi::Number::New(env, llvm::Attribute::AttrKind::ReadNone));
|
|
52
|
-
attributeKinds.Set("ReadOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::ReadOnly));
|
|
53
|
-
attributeKinds.Set("Returned", Napi::Number::New(env, llvm::Attribute::AttrKind::Returned));
|
|
54
|
-
attributeKinds.Set("ReturnsTwice", Napi::Number::New(env, llvm::Attribute::AttrKind::ReturnsTwice));
|
|
55
|
-
attributeKinds.Set("SExt", Napi::Number::New(env, llvm::Attribute::AttrKind::SExt));
|
|
56
|
-
attributeKinds.Set("SafeStack", Napi::Number::New(env, llvm::Attribute::AttrKind::SafeStack));
|
|
57
|
-
attributeKinds.Set("SanitizeAddress", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeAddress));
|
|
58
|
-
attributeKinds.Set("SanitizeHWAddress", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeHWAddress));
|
|
59
|
-
attributeKinds.Set("SanitizeMemTag", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeMemTag));
|
|
60
|
-
attributeKinds.Set("SanitizeMemory", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeMemory));
|
|
61
|
-
attributeKinds.Set("SanitizeThread", Napi::Number::New(env, llvm::Attribute::AttrKind::SanitizeThread));
|
|
62
|
-
attributeKinds.Set("ShadowCallStack", Napi::Number::New(env, llvm::Attribute::AttrKind::ShadowCallStack));
|
|
63
|
-
attributeKinds.Set("Speculatable", Napi::Number::New(env, llvm::Attribute::AttrKind::Speculatable));
|
|
64
|
-
attributeKinds.Set("SpeculativeLoadHardening",
|
|
65
|
-
Napi::Number::New(env, llvm::Attribute::AttrKind::SpeculativeLoadHardening));
|
|
66
|
-
attributeKinds.Set("StackProtect", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtect));
|
|
67
|
-
attributeKinds.Set("StackProtectReq", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtectReq));
|
|
68
|
-
attributeKinds.Set("StackProtectStrong", Napi::Number::New(env, llvm::Attribute::AttrKind::StackProtectStrong));
|
|
69
|
-
attributeKinds.Set("StrictFP", Napi::Number::New(env, llvm::Attribute::AttrKind::StrictFP));
|
|
70
|
-
attributeKinds.Set("SwiftAsync", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftAsync));
|
|
71
|
-
attributeKinds.Set("SwiftError", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftError));
|
|
72
|
-
attributeKinds.Set("SwiftSelf", Napi::Number::New(env, llvm::Attribute::AttrKind::SwiftSelf));
|
|
73
|
-
attributeKinds.Set("UWTable", Napi::Number::New(env, llvm::Attribute::AttrKind::UWTable));
|
|
74
|
-
attributeKinds.Set("WillReturn", Napi::Number::New(env, llvm::Attribute::AttrKind::WillReturn));
|
|
75
|
-
attributeKinds.Set("WriteOnly", Napi::Number::New(env, llvm::Attribute::AttrKind::WriteOnly));
|
|
76
|
-
attributeKinds.Set("LastEnumAttr", Napi::Number::New(env, llvm::Attribute::AttrKind::LastEnumAttr));
|
|
77
|
-
attributeKinds.Set("ByRef", Napi::Number::New(env, llvm::Attribute::AttrKind::ByRef));
|
|
78
|
-
attributeKinds.Set("ByVal", Napi::Number::New(env, llvm::Attribute::AttrKind::ByVal));
|
|
79
|
-
attributeKinds.Set("ElementType", Napi::Number::New(env, llvm::Attribute::AttrKind::ElementType));
|
|
80
|
-
attributeKinds.Set("InAlloca", Napi::Number::New(env, llvm::Attribute::AttrKind::InAlloca));
|
|
81
|
-
attributeKinds.Set("Preallocated", Napi::Number::New(env, llvm::Attribute::AttrKind::Preallocated));
|
|
82
|
-
attributeKinds.Set("LastTypeAttr", Napi::Number::New(env, llvm::Attribute::AttrKind::LastTypeAttr));
|
|
83
|
-
attributeKinds.Set("Alignment", Napi::Number::New(env, llvm::Attribute::AttrKind::Alignment));
|
|
84
|
-
attributeKinds.Set("AllocSize", Napi::Number::New(env, llvm::Attribute::AttrKind::AllocSize));
|
|
85
|
-
attributeKinds.Set("Dereferenceable", Napi::Number::New(env, llvm::Attribute::AttrKind::Dereferenceable));
|
|
86
|
-
attributeKinds.Set("DereferenceableOrNull",
|
|
87
|
-
Napi::Number::New(env, llvm::Attribute::AttrKind::DereferenceableOrNull));
|
|
88
|
-
attributeKinds.Set("StackAlignment", Napi::Number::New(env, llvm::Attribute::AttrKind::StackAlignment));
|
|
89
|
-
attributeKinds.Set("VScaleRange", Napi::Number::New(env, llvm::Attribute::AttrKind::VScaleRange));
|
|
8
|
+
|
|
9
|
+
#define GET_ATTR_NAMES
|
|
10
|
+
#define ATTRIBUTE_ENUM(EnumName, lower) attributeKinds.Set(#EnumName, Napi::Number::New(env, llvm::Attribute::AttrKind::EnumName));
|
|
11
|
+
#include "llvm/IR/Attributes.inc"
|
|
12
|
+
#undef GET_ATTR_NAMES
|
|
13
|
+
#undef ATTRIBUTE_ENUM
|
|
90
14
|
|
|
91
15
|
Napi::Function func = DefineClass(env, "Attribute", {
|
|
92
16
|
StaticValue("AttrKind", attributeKinds),
|
package/src/IR/DataLayout.cpp
CHANGED
|
@@ -53,7 +53,7 @@ Napi::Value DataLayout::getTypeAllocSize(const Napi::CallbackInfo &info) {
|
|
|
53
53
|
if (info.Length() == 1 && Type::IsClassOf(info[0])) {
|
|
54
54
|
llvm::Type *type = Type::Extract(info[0]);
|
|
55
55
|
auto allocSize = dataLayout->getTypeAllocSize(type);
|
|
56
|
-
return Napi::Number::New(env, double(allocSize.
|
|
56
|
+
return Napi::Number::New(env, static_cast<double>(allocSize.getFixedValue()));
|
|
57
57
|
}
|
|
58
58
|
throw Napi::TypeError::New(env, ErrMsg::Class::DataLayout::getTypeAllocSize);
|
|
59
59
|
}
|
package/src/IR/DerivedTypes.cpp
CHANGED
|
@@ -565,7 +565,8 @@ void PointerType::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
565
565
|
InstanceMethod("isIntegerTy", &PointerType::isIntegerTy),
|
|
566
566
|
InstanceMethod("isVoidTy", &PointerType::isVoidTy),
|
|
567
567
|
InstanceMethod("getTypeID", &PointerType::getTypeID),
|
|
568
|
-
InstanceMethod("
|
|
568
|
+
InstanceMethod("getNonOpaquePointerElementType", &PointerType::getNonOpaquePointerElementType),
|
|
569
|
+
InstanceMethod("isOpaque", &PointerType::isOpaque)
|
|
569
570
|
});
|
|
570
571
|
constructor = Napi::Persistent(func);
|
|
571
572
|
constructor.SuppressDestruct();
|
|
@@ -599,22 +600,38 @@ PointerType::PointerType(const Napi::CallbackInfo &info) : ObjectWrap(info) {
|
|
|
599
600
|
|
|
600
601
|
Napi::Value PointerType::get(const Napi::CallbackInfo &info) {
|
|
601
602
|
Napi::Env env = info.Env();
|
|
602
|
-
if (info.Length() < 2 || !
|
|
603
|
+
if (info.Length() < 2 || !info[1].IsNumber()) {
|
|
603
604
|
throw Napi::TypeError::New(env, ErrMsg::Class::PointerType::get);
|
|
604
605
|
}
|
|
605
|
-
llvm::Type *type = Type::Extract(info[0]);
|
|
606
606
|
uint32_t addrSpace = info[1].As<Napi::Number>();
|
|
607
|
-
llvm::PointerType *pointerType
|
|
607
|
+
llvm::PointerType *pointerType;
|
|
608
|
+
if (LLVMContext::IsClassOf(info[0])) {
|
|
609
|
+
llvm::LLVMContext &context = LLVMContext::Extract(info[0]);
|
|
610
|
+
pointerType = llvm::PointerType::get(context, addrSpace);
|
|
611
|
+
} else if (Type::IsClassOf(info[0])) {
|
|
612
|
+
llvm::Type *type = Type::Extract(info[0]);
|
|
613
|
+
pointerType = llvm::PointerType::get(type, addrSpace);
|
|
614
|
+
} else {
|
|
615
|
+
throw Napi::TypeError::New(env, ErrMsg::Class::PointerType::get);
|
|
616
|
+
}
|
|
608
617
|
return PointerType::New(env, pointerType);
|
|
609
618
|
}
|
|
610
619
|
|
|
611
620
|
Napi::Value PointerType::getUnqual(const Napi::CallbackInfo &info) {
|
|
612
621
|
Napi::Env env = info.Env();
|
|
613
|
-
if (info.Length() == 0
|
|
622
|
+
if (info.Length() == 0) {
|
|
623
|
+
throw Napi::TypeError::New(env, ErrMsg::Class::PointerType::getUnqual);
|
|
624
|
+
}
|
|
625
|
+
llvm::PointerType *pointerType;
|
|
626
|
+
if (LLVMContext::IsClassOf(info[0])) {
|
|
627
|
+
llvm::LLVMContext &context = LLVMContext::Extract(info[0]);
|
|
628
|
+
pointerType = llvm::PointerType::getUnqual(context);
|
|
629
|
+
} else if (Type::IsClassOf(info[0])) {
|
|
630
|
+
llvm::Type *type = Type::Extract(info[0]);
|
|
631
|
+
pointerType = llvm::PointerType::getUnqual(type);
|
|
632
|
+
} else {
|
|
614
633
|
throw Napi::TypeError::New(env, ErrMsg::Class::PointerType::getUnqual);
|
|
615
634
|
}
|
|
616
|
-
llvm::Type *type = Type::Extract(info[0]);
|
|
617
|
-
llvm::PointerType *pointerType = llvm::PointerType::getUnqual(type);
|
|
618
635
|
return PointerType::New(env, pointerType);
|
|
619
636
|
}
|
|
620
637
|
|
|
@@ -647,6 +664,10 @@ Napi::Value PointerType::getTypeID(const Napi::CallbackInfo &info) {
|
|
|
647
664
|
return Napi::Number::New(info.Env(), pointerType->getTypeID());
|
|
648
665
|
}
|
|
649
666
|
|
|
650
|
-
Napi::Value PointerType::
|
|
651
|
-
return Type::New(info.Env(), pointerType->
|
|
667
|
+
Napi::Value PointerType::getNonOpaquePointerElementType(const Napi::CallbackInfo &info) {
|
|
668
|
+
return Type::New(info.Env(), pointerType->getNonOpaquePointerElementType());
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
Napi::Value PointerType::isOpaque(const Napi::CallbackInfo &info) {
|
|
672
|
+
return Napi::Boolean::New(info.Env(), pointerType->isOpaque());
|
|
652
673
|
}
|
package/src/IR/Function.cpp
CHANGED
|
@@ -111,7 +111,7 @@ void Function::addBasicBlock(const Napi::CallbackInfo &info) {
|
|
|
111
111
|
throw Napi::TypeError::New(env, ErrMsg::Class::Function::addBasicBlock);
|
|
112
112
|
}
|
|
113
113
|
llvm::BasicBlock *basicBlock = BasicBlock::Extract(info[0]);
|
|
114
|
-
function->
|
|
114
|
+
function->insert(function->end(), basicBlock);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
Napi::Value Function::getEntryBlock(const Napi::CallbackInfo &info) {
|
|
@@ -129,7 +129,9 @@ void Function::insertAfter(const Napi::CallbackInfo &info) {
|
|
|
129
129
|
}
|
|
130
130
|
llvm::BasicBlock *where = BasicBlock::Extract(info[0]);
|
|
131
131
|
llvm::BasicBlock *bb = BasicBlock::Extract(info[1]);
|
|
132
|
-
|
|
132
|
+
auto it = where->getIterator();
|
|
133
|
+
++it;
|
|
134
|
+
function->insert(it, bb);
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
void Function::deleteBody(const Napi::CallbackInfo &info) {
|
package/src/IR/IRBuilder.cpp
CHANGED
|
@@ -53,6 +53,7 @@ void IRBuilder::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
53
53
|
InstanceMethod("getDoubleTy", &IRBuilder::getTypeFactory<&LLVMIRBuilder::getDoubleTy>),
|
|
54
54
|
InstanceMethod("getVoidTy", &IRBuilder::getTypeFactory<&LLVMIRBuilder::getVoidTy>),
|
|
55
55
|
InstanceMethod("getInt8PtrTy", &IRBuilder::getInt8PtrTy),
|
|
56
|
+
InstanceMethod("getPtrTy", &IRBuilder::getPtrTy),
|
|
56
57
|
InstanceMethod("getIntPtrTy", &IRBuilder::getIntPtrTy),
|
|
57
58
|
|
|
58
59
|
//===--------------------------------------------------------------------===//
|
|
@@ -395,6 +396,17 @@ Napi::Value IRBuilder::getInt8PtrTy(const Napi::CallbackInfo &info) {
|
|
|
395
396
|
throw Napi::TypeError::New(env, ErrMsg::Class::IRBuilder::getInt8PtrTy);
|
|
396
397
|
}
|
|
397
398
|
|
|
399
|
+
Napi::Value IRBuilder::getPtrTy(const Napi::CallbackInfo &info) {
|
|
400
|
+
Napi::Env env = info.Env();
|
|
401
|
+
unsigned argsLen = info.Length();
|
|
402
|
+
if (argsLen == 0 || argsLen == 1 && info[0].IsNumber()) {
|
|
403
|
+
unsigned addrSpace = argsLen == 1 ? info[0].As<Napi::Number>() : 0;
|
|
404
|
+
llvm::PointerType *type = builder->getPtrTy(addrSpace);
|
|
405
|
+
return PointerType::New(env, type);
|
|
406
|
+
}
|
|
407
|
+
throw Napi::TypeError::New(env, ErrMsg::Class::IRBuilder::getPtrTy);
|
|
408
|
+
}
|
|
409
|
+
|
|
398
410
|
Napi::Value IRBuilder::getIntPtrTy(const Napi::CallbackInfo &info) {
|
|
399
411
|
Napi::Env env = info.Env();
|
|
400
412
|
unsigned argsLen = info.Length();
|
|
@@ -486,7 +498,7 @@ Napi::Value IRBuilder::CreateInvoke(const Napi::CallbackInfo &info) {
|
|
|
486
498
|
llvm::BasicBlock *normalDest = BasicBlock::Extract(info[1]);
|
|
487
499
|
llvm::BasicBlock *unwindDest = BasicBlock::Extract(info[2]);
|
|
488
500
|
std::string name = argsLen == 4 ? std::string(info[3].As<Napi::String>()) : "";
|
|
489
|
-
invokeInst = builder->CreateInvoke(callee, normalDest, unwindDest,
|
|
501
|
+
invokeInst = builder->CreateInvoke(callee, normalDest, unwindDest, {}, name);
|
|
490
502
|
} else if (argsLen == 4 && Function::IsClassOf(info[0]) && BasicBlock::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) && info[3].IsArray() ||
|
|
491
503
|
argsLen == 5 && Function::IsClassOf(info[0]) && BasicBlock::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) && info[3].IsArray() && info[4].IsString()) {
|
|
492
504
|
if (assembleArray<WrappedValue>(info[3].As<Napi::Array>(), calleeArgs)) {
|
|
@@ -502,7 +514,7 @@ Napi::Value IRBuilder::CreateInvoke(const Napi::CallbackInfo &info) {
|
|
|
502
514
|
llvm::BasicBlock *normalDest = BasicBlock::Extract(info[1]);
|
|
503
515
|
llvm::BasicBlock *unwindDest = BasicBlock::Extract(info[2]);
|
|
504
516
|
std::string name = argsLen == 4 ? std::string(info[3].As<Napi::String>()) : "";
|
|
505
|
-
invokeInst = builder->CreateInvoke(callee, normalDest, unwindDest,
|
|
517
|
+
invokeInst = builder->CreateInvoke(callee, normalDest, unwindDest, {}, name);
|
|
506
518
|
} else if (argsLen == 4 && FunctionCallee::IsClassOf(info[0]) && BasicBlock::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) && info[3].IsArray() ||
|
|
507
519
|
argsLen == 5 && FunctionCallee::IsClassOf(info[0]) && BasicBlock::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) && info[3].IsArray() && info[4].IsString()) {
|
|
508
520
|
if (assembleArray<WrappedValue>(info[3].As<Napi::Array>(), calleeArgs)) {
|
|
@@ -521,7 +533,7 @@ Napi::Value IRBuilder::CreateInvoke(const Napi::CallbackInfo &info) {
|
|
|
521
533
|
llvm::BasicBlock *normalDest = BasicBlock::Extract(info[2]);
|
|
522
534
|
llvm::BasicBlock *unwindDest = BasicBlock::Extract(info[3]);
|
|
523
535
|
std::string name = argsLen == 5 ? std::string(info[4].As<Napi::String>()) : "";
|
|
524
|
-
invokeInst = builder->CreateInvoke(funcType, callee, normalDest, unwindDest,
|
|
536
|
+
invokeInst = builder->CreateInvoke(funcType, callee, normalDest, unwindDest, {}, name);
|
|
525
537
|
} else if (argsLen == 5 && FunctionType::IsClassOf(info[0]) && Function::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) &&
|
|
526
538
|
BasicBlock::IsClassOf(info[3]) && info[4].IsArray() ||
|
|
527
539
|
argsLen == 6 && FunctionType::IsClassOf(info[0]) && Function::IsClassOf(info[1]) && BasicBlock::IsClassOf(info[2]) &&
|
|
@@ -699,7 +711,7 @@ Napi::Value IRBuilder::CreateCall(const Napi::CallbackInfo &info) {
|
|
|
699
711
|
argsLen == 2 && Function::IsClassOf(info[0]) && info[1].IsString()) {
|
|
700
712
|
llvm::Function *callee = Function::Extract(info[0]);
|
|
701
713
|
std::string name = argsLen == 2 ? std::string(info[1].As<Napi::String>()) : "";
|
|
702
|
-
callInst = builder->CreateCall(callee,
|
|
714
|
+
callInst = builder->CreateCall(callee, {}, name);
|
|
703
715
|
} else if (argsLen == 2 && Function::IsClassOf(info[0]) && info[1].IsArray() ||
|
|
704
716
|
argsLen == 3 && Function::IsClassOf(info[0]) && info[1].IsArray() && info[2].IsString()) {
|
|
705
717
|
if (assembleArray<WrappedValue>(info[1].As<Napi::Array>(), calleeArgs)) {
|
|
@@ -711,7 +723,7 @@ Napi::Value IRBuilder::CreateCall(const Napi::CallbackInfo &info) {
|
|
|
711
723
|
argsLen == 2 && FunctionCallee::IsClassOf(info[0]) && info[1].IsString()) {
|
|
712
724
|
llvm::FunctionCallee callee = FunctionCallee::Extract(info[0]);
|
|
713
725
|
std::string name = argsLen == 2 ? std::string(info[1].As<Napi::String>()) : "";
|
|
714
|
-
callInst = builder->CreateCall(callee,
|
|
726
|
+
callInst = builder->CreateCall(callee, {}, name);
|
|
715
727
|
} else if (argsLen == 2 && FunctionCallee::IsClassOf(info[0]) && info[1].IsArray() ||
|
|
716
728
|
argsLen == 3 && FunctionCallee::IsClassOf(info[0]) && info[1].IsArray() && info[2].IsString()) {
|
|
717
729
|
if (assembleArray<WrappedValue>(info[1].As<Napi::Array>(), calleeArgs)) {
|
|
@@ -724,7 +736,7 @@ Napi::Value IRBuilder::CreateCall(const Napi::CallbackInfo &info) {
|
|
|
724
736
|
llvm::FunctionType *funcType = FunctionType::Extract(info[0]);
|
|
725
737
|
llvm::Value *callee = Value::Extract(info[1]);
|
|
726
738
|
std::string name = argsLen == 3 ? std::string(info[2].As<Napi::String>()) : "";
|
|
727
|
-
callInst = builder->CreateCall(funcType, callee,
|
|
739
|
+
callInst = builder->CreateCall(funcType, callee, {}, name);
|
|
728
740
|
} else if (argsLen == 3 && FunctionType::IsClassOf(info[0]) && Value::IsClassOf(info[1]) && info[2].IsArray() ||
|
|
729
741
|
argsLen == 4 && FunctionType::IsClassOf(info[0]) && Value::IsClassOf(info[1]) && info[2].IsArray() && info[3].IsString()) {
|
|
730
742
|
if (assembleArray<WrappedValue>(info[2].As<Napi::Array>(), calleeArgs)) {
|
package/src/IR/Intrinsic.cpp
CHANGED
|
@@ -107,7 +107,6 @@ void Intrinsic::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
107
107
|
intrinsicNS.Set("expect_with_probability", Napi::Number::New(env, llvm::Intrinsic::expect_with_probability));
|
|
108
108
|
intrinsicNS.Set("fabs", Napi::Number::New(env, llvm::Intrinsic::fabs));
|
|
109
109
|
intrinsicNS.Set("floor", Napi::Number::New(env, llvm::Intrinsic::floor));
|
|
110
|
-
intrinsicNS.Set("flt_rounds", Napi::Number::New(env, llvm::Intrinsic::flt_rounds));
|
|
111
110
|
intrinsicNS.Set("fma", Napi::Number::New(env, llvm::Intrinsic::fma));
|
|
112
111
|
intrinsicNS.Set("fmuladd", Napi::Number::New(env, llvm::Intrinsic::fmuladd));
|
|
113
112
|
intrinsicNS.Set("fptosi_sat", Napi::Number::New(env, llvm::Intrinsic::fptosi_sat));
|
package/src/IR/Type.cpp
CHANGED
|
@@ -59,7 +59,6 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
59
59
|
typeID.Set("VoidTyID", Napi::Number::New(env, llvm::Type::TypeID::VoidTyID));
|
|
60
60
|
typeID.Set("LabelTyID", Napi::Number::New(env, llvm::Type::TypeID::LabelTyID));
|
|
61
61
|
typeID.Set("MetadataTyID", Napi::Number::New(env, llvm::Type::TypeID::MetadataTyID));
|
|
62
|
-
typeID.Set("X86_MMXTyID", Napi::Number::New(env, llvm::Type::TypeID::X86_MMXTyID));
|
|
63
62
|
typeID.Set("TokenTyID", Napi::Number::New(env, llvm::Type::TypeID::TokenTyID));
|
|
64
63
|
typeID.Set("IntegerTyID", Napi::Number::New(env, llvm::Type::TypeID::IntegerTyID));
|
|
65
64
|
typeID.Set("FunctionTyID", Napi::Number::New(env, llvm::Type::TypeID::FunctionTyID));
|
|
@@ -81,7 +80,6 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
81
80
|
StaticMethod("getX86_FP80Ty", &getTypeFactory<&llvm::Type::getX86_FP80Ty>),
|
|
82
81
|
StaticMethod("getFP128Ty", &getTypeFactory<&llvm::Type::getFP128Ty>),
|
|
83
82
|
StaticMethod("getPPC_FP128Ty", &getTypeFactory<&llvm::Type::getPPC_FP128Ty>),
|
|
84
|
-
StaticMethod("getX86_MMXTy", &getTypeFactory<&llvm::Type::getX86_MMXTy>),
|
|
85
83
|
StaticMethod("getTokenTy", &getTypeFactory<&llvm::Type::getTokenTy>),
|
|
86
84
|
StaticMethod("getIntNTy", &Type::getIntNTy),
|
|
87
85
|
StaticMethod("getInt1Ty", &getIntTypeFactory<&llvm::Type::getInt1Ty>),
|
|
@@ -97,7 +95,6 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
97
95
|
StaticMethod("getX86_FP80PtrTy", &getPointerTypeFactory<&llvm::Type::getX86_FP80PtrTy>),
|
|
98
96
|
StaticMethod("getFP128PtrTy", &getPointerTypeFactory<&llvm::Type::getFP128PtrTy>),
|
|
99
97
|
StaticMethod("getPPC_FP128PtrTy", &getPointerTypeFactory<&llvm::Type::getPPC_FP128PtrTy>),
|
|
100
|
-
StaticMethod("getX86_MMXPtrTy", &getPointerTypeFactory<&llvm::Type::getX86_MMXPtrTy>),
|
|
101
98
|
StaticMethod("getInt1PtrTy", &getPointerTypeFactory<&llvm::Type::getInt1PtrTy>),
|
|
102
99
|
StaticMethod("getInt8PtrTy", &getPointerTypeFactory<&llvm::Type::getInt8PtrTy>),
|
|
103
100
|
StaticMethod("getInt16PtrTy", &getPointerTypeFactory<&llvm::Type::getInt16PtrTy>),
|
|
@@ -113,7 +110,6 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
113
110
|
InstanceMethod("isFP128Ty", &Type::isTypeFactory<&llvm::Type::isFP128Ty>),
|
|
114
111
|
InstanceMethod("isPPC_FP128Ty", &Type::isTypeFactory<&llvm::Type::isPPC_FP128Ty>),
|
|
115
112
|
InstanceMethod("isFloatingPointTy", &Type::isTypeFactory<&llvm::Type::isFloatingPointTy>),
|
|
116
|
-
InstanceMethod("isX86_MMXTy", &Type::isTypeFactory<&llvm::Type::isX86_MMXTy>),
|
|
117
113
|
InstanceMethod("isLabelTy", &Type::isTypeFactory<&llvm::Type::isLabelTy>),
|
|
118
114
|
InstanceMethod("isMetadataTy", &Type::isTypeFactory<&llvm::Type::isMetadataTy>),
|
|
119
115
|
InstanceMethod("isTokenTy", &Type::isTypeFactory<&llvm::Type::isTokenTy>),
|
|
@@ -122,6 +118,7 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
122
118
|
InstanceMethod("isStructTy", &Type::isTypeFactory<&llvm::Type::isStructTy>),
|
|
123
119
|
InstanceMethod("isArrayTy", &Type::isTypeFactory<&llvm::Type::isArrayTy>),
|
|
124
120
|
InstanceMethod("isPointerTy", &Type::isTypeFactory<&llvm::Type::isPointerTy>),
|
|
121
|
+
InstanceMethod("isOpaquePointerTy", &Type::isTypeFactory<&llvm::Type::isOpaquePointerTy>),
|
|
125
122
|
InstanceMethod("isVectorTy", &Type::isTypeFactory<&llvm::Type::isVectorTy>),
|
|
126
123
|
InstanceMethod("isEmptyTy", &Type::isTypeFactory<&llvm::Type::isEmptyTy>),
|
|
127
124
|
InstanceMethod("isFirstClassType", &Type::isTypeFactory<&llvm::Type::isFirstClassType>),
|
|
@@ -129,7 +126,7 @@ void Type::Init(Napi::Env env, Napi::Object &exports) {
|
|
|
129
126
|
InstanceMethod("isAggregateType", &Type::isTypeFactory<&llvm::Type::isAggregateType>),
|
|
130
127
|
InstanceMethod("getPointerTo", &Type::getPointerTo),
|
|
131
128
|
InstanceMethod("getPrimitiveSizeInBits", &Type::getPrimitiveSizeInBits),
|
|
132
|
-
InstanceMethod("
|
|
129
|
+
InstanceMethod("getNonOpaquePointerElementType", &Type::getNonOpaquePointerElementType),
|
|
133
130
|
StaticMethod("isSameType", &Type::isSameType)
|
|
134
131
|
});
|
|
135
132
|
constructor = Napi::Persistent(func);
|
|
@@ -219,8 +216,8 @@ Napi::Value Type::isIntegerTy(const Napi::CallbackInfo &info) {
|
|
|
219
216
|
return Napi::Boolean::New(env, result);
|
|
220
217
|
}
|
|
221
218
|
|
|
222
|
-
Napi::Value Type::
|
|
223
|
-
return Type::New(info.Env(), type->
|
|
219
|
+
Napi::Value Type::getNonOpaquePointerElementType(const Napi::CallbackInfo &info) {
|
|
220
|
+
return Type::New(info.Env(), type->getNonOpaquePointerElementType());
|
|
224
221
|
}
|
|
225
222
|
|
|
226
223
|
static bool isSameType(llvm::Type *type1, llvm::Type *type2) {
|
|
@@ -248,7 +245,10 @@ static bool isSameType(llvm::Type *type1, llvm::Type *type2) {
|
|
|
248
245
|
}
|
|
249
246
|
}
|
|
250
247
|
} else if (type1->isPointerTy()) {
|
|
251
|
-
|
|
248
|
+
if (type1->isOpaquePointerTy() || type2->isOpaquePointerTy()) {
|
|
249
|
+
return type1->isOpaquePointerTy() && type2->isOpaquePointerTy();
|
|
250
|
+
}
|
|
251
|
+
return isSameType(type1->getNonOpaquePointerElementType(), type2->getNonOpaquePointerElementType());
|
|
252
252
|
} else if (type1->isStructTy()) {
|
|
253
253
|
unsigned numElements = type1->getStructNumElements();
|
|
254
254
|
if (numElements != type2->getStructNumElements()) {
|
|
@@ -45,7 +45,8 @@ Napi::Value Target::createTargetMachine(const Napi::CallbackInfo &info) {
|
|
|
45
45
|
features = info[2].As<Napi::String>();
|
|
46
46
|
}
|
|
47
47
|
llvm::TargetOptions options{};
|
|
48
|
-
llvm::TargetMachine *targetMachinePtr = target->createTargetMachine(
|
|
48
|
+
llvm::TargetMachine *targetMachinePtr = target->createTargetMachine(
|
|
49
|
+
targetTriple, cpu, features, options, std::optional<llvm::Reloc::Model>{});
|
|
49
50
|
return TargetMachine::New(env, targetMachinePtr);
|
|
50
51
|
}
|
|
51
52
|
|
package/src/llvm-bindings.cpp
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
#include <cstdio>
|
|
2
|
+
#include <memory>
|
|
3
|
+
#include <stdexcept>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
1
6
|
#include "ADT/index.h"
|
|
2
7
|
#include "BinaryFormat/index.h"
|
|
3
8
|
#include "Bitcode/index.h"
|
|
@@ -9,7 +14,27 @@
|
|
|
9
14
|
#include "Support/index.h"
|
|
10
15
|
#include "Target/index.h"
|
|
11
16
|
|
|
17
|
+
template<typename ... Args>
|
|
18
|
+
std::string string_format( const std::string& format, Args ... args )
|
|
19
|
+
{
|
|
20
|
+
int size_s = std::snprintf( nullptr, 0, format.c_str(), args ... ) + 1; // Extra space for '\0'
|
|
21
|
+
if( size_s <= 0 ){ throw std::runtime_error( "Error during formatting." ); }
|
|
22
|
+
auto size = static_cast<size_t>( size_s );
|
|
23
|
+
std::unique_ptr<char[]> buf( new char[ size ] );
|
|
24
|
+
std::snprintf( buf.get(), size, format.c_str(), args ... );
|
|
25
|
+
return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static std::unique_ptr<Napi::Env> node_env;
|
|
29
|
+
|
|
30
|
+
void llvm_bindings_assert(const char* e, const char* file, int line)
|
|
31
|
+
{
|
|
32
|
+
throw Napi::Error::New(
|
|
33
|
+
*node_env, string_format("%s:%d: failed assertion `%s'\n", file, line, e));
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
37
|
+
node_env = std::make_unique<Napi::Env>(env);
|
|
13
38
|
InitADT(env, exports);
|
|
14
39
|
InitBinaryFormat(env, exports);
|
|
15
40
|
InitBitCode(env, exports);
|
package/test/exception.ts
CHANGED
|
@@ -27,7 +27,7 @@ export default function testException() {
|
|
|
27
27
|
const tmp2 = builder.CreateBitCast(tmp1, llvm.PointerType.getUnqual(builder.getInt8PtrTy()));
|
|
28
28
|
builder.CreateStore(
|
|
29
29
|
builder.CreateInBoundsGEP(
|
|
30
|
-
errMsgStr.
|
|
30
|
+
errMsgStr.getValueType(),
|
|
31
31
|
errMsgStr,
|
|
32
32
|
[builder.getInt64(0), builder.getInt64(0)]
|
|
33
33
|
),
|