Skip to content

Commit 8a3fd8f

Browse files
author
Micha Reiser
authored
Merge branch 'master' into constant-fp-get-type-overload
2 parents a317ed1 + 2d6edc7 commit 8a3fd8f

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ language: node_js
22
node_js:
33
- "11"
44
- "10"
5-
- "9"
65
- "8"
7-
- "7"
86
- "6"
97
cache: yarn
108
env:
@@ -20,7 +18,7 @@ before_install:
2018
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
2119
- echo $LLVM_DEB | sudo tee -a /etc/apt/sources.list
2220
- sudo apt-get update -qq
23-
- sudo apt-get install libedit-dev llvm-$LLVM_VERSION llvm-$LLVM_VERSION-dev
21+
- sudo apt-get install libedit-dev llvm-$LLVM_VERSION llvm-$LLVM_VERSION-dev clang-$LLVM_VERSION llvm-$LLVM_VERSION-tools
2422
- npm config set cmake_LLVM_DIR $(llvm-config-$LLVM_VERSION --cmakedir)
2523
deploy:
2624
provider: npm

llvm-node.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ declare namespace llvm {
667667
private __marker: number;
668668
}
669669

670+
interface FunctionCallee {
671+
callee: Value;
672+
functionType: FunctionType;
673+
}
674+
670675
class Module {
671676
empty: boolean;
672677
readonly name: string;
@@ -683,7 +688,7 @@ declare namespace llvm {
683688

684689
getFunction(name: string): Function | undefined;
685690

686-
getOrInsertFunction(name: string, functionType: FunctionType): Constant;
691+
getOrInsertFunction(name: string, functionType: FunctionType): FunctionCallee;
687692

688693
getGlobalVariable(name: string, allowInternal?: boolean): GlobalVariable;
689694

src/ir/module.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ NAN_METHOD(ModuleWrapper::getOrInsertFunction) {
9393
std::string name = ToString(info[0]);
9494
auto* fnType = FunctionTypeWrapper::FromValue(info[1])->getFunctionType();
9595

96-
info.GetReturnValue().Set(ConstantWrapper::of(module->getOrInsertFunction(name, fnType)));
96+
auto functionCallee = Nan::New<v8::Object>();
97+
98+
#if LLVM_VERSION_MAJOR < 9
99+
Nan::Set(functionCallee, Nan::New("callee").ToLocalChecked(), ConstantWrapper::of(module->getOrInsertFunction(name, fnType)));
100+
Nan::Set(functionCallee, Nan::New("functionType").ToLocalChecked(), FunctionTypeWrapper::of(fnType));
101+
#else
102+
auto llvmCallee = module->getOrInsertFunction(name, fnType);
103+
Nan::Set(functionCallee, Nan::New("callee").ToLocalChecked(), ValueWrapper::of(llvmCallee.getCallee()));
104+
Nan::Set(functionCallee, Nan::New("functionType").ToLocalChecked(), FunctionTypeWrapper::of(llvmCallee.getFunctionType()));
105+
#endif
106+
107+
Nan::EscapableHandleScope scope {};
108+
info.GetReturnValue().Set(scope.Escape(functionCallee));
97109
}
98110

99111
NAN_METHOD(ModuleWrapper::getGlobalVariable) {

test/ir/module.spec.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as llvm from "../../";
2-
import { createModule, createBuilder, createBuilderWithBlock } from "../test-utils";
2+
import { createModule, createBuilder } from "../test-utils";
33

44
describe("ir/module", () => {
55
describe("constructor", () => {
@@ -141,30 +141,32 @@ describe("ir/module", () => {
141141
describe("getOrInsertFunction", () => {
142142
test("returns a new function if not yet existing in the module", () => {
143143
const { module, context } = createModule();
144-
145-
const fun = module.getOrInsertFunction(
146-
"fib",
147-
llvm.FunctionType.get(llvm.Type.getDoubleTy(context), [llvm.Type.getDoubleTy(context)], false)
144+
const functionType = llvm.FunctionType.get(
145+
llvm.Type.getDoubleTy(context),
146+
[llvm.Type.getDoubleTy(context)],
147+
false
148148
);
149149

150-
expect(fun).toBeDefined();
151-
expect(module.getFunction("fib")).toEqual(fun);
150+
const functionCallee = module.getOrInsertFunction("fib", functionType);
151+
152+
expect(functionCallee).toBeDefined();
153+
expect(module.getFunction("fib")).toEqual(functionCallee.callee);
154+
expect(functionCallee.functionType).toEqual(functionType);
152155
});
153156

154157
test("returns the existing function if a function with the given name already exist", () => {
155158
const { module, context } = createModule();
156159

157-
const fun = llvm.Function.create(
158-
llvm.FunctionType.get(llvm.Type.getDoubleTy(context), [], false),
159-
llvm.LinkageTypes.ExternalLinkage,
160-
"sin",
161-
module
162-
);
163-
const queriedFn = module.getOrInsertFunction(
160+
const functionType = llvm.FunctionType.get(llvm.Type.getDoubleTy(context), [], false);
161+
const fun = llvm.Function.create(functionType, llvm.LinkageTypes.ExternalLinkage, "sin", module);
162+
163+
const functionCallee = module.getOrInsertFunction(
164164
"sin",
165165
llvm.FunctionType.get(llvm.Type.getDoubleTy(context), [], false)
166166
);
167-
expect(queriedFn).toEqual(fun);
167+
168+
expect(functionCallee.callee).toEqual(fun);
169+
expect(functionCallee.functionType).toEqual(functionType);
168170
});
169171
});
170172

@@ -209,22 +211,22 @@ describe("ir/module", () => {
209211

210212
describe("getTypeByName", () => {
211213
test("returns null if a type with the given name does not exist", () => {
212-
const {module, context} = createModule();
214+
const { module, context } = createModule();
213215

214216
const type = module.getTypeByName("DoesNotExist");
215217

216218
expect(type).toBeNull();
217219
});
218220

219221
test("returns the type with the given name if it exists", () => {
220-
const {module, context} = createModule();
221-
const structType = llvm.StructType.create(context, "IntTuple");
222-
structType.setBody([llvm.Type.getInt32Ty(context), llvm.Type.getInt32Ty(context)]);
222+
const { module, context } = createModule();
223+
const structType = llvm.StructType.create(context, "IntTuple");
224+
structType.setBody([llvm.Type.getInt32Ty(context), llvm.Type.getInt32Ty(context)]);
223225

224-
const retrieved = module.getTypeByName("IntTuple");
226+
const retrieved = module.getTypeByName("IntTuple");
225227

226-
expect(retrieved).toBeInstanceOf(llvm.StructType);
227-
expect(retrieved).toEqual(structType);
228+
expect(retrieved).toBeInstanceOf(llvm.StructType);
229+
expect(retrieved).toEqual(structType);
228230
});
229231
});
230232
});

0 commit comments

Comments
 (0)