|
1 | 1 | import * as llvm from "../../"; |
2 | | -import { createModule, createBuilder, createBuilderWithBlock } from "../test-utils"; |
| 2 | +import { createModule, createBuilder } from "../test-utils"; |
3 | 3 |
|
4 | 4 | describe("ir/module", () => { |
5 | 5 | describe("constructor", () => { |
@@ -141,30 +141,32 @@ describe("ir/module", () => { |
141 | 141 | describe("getOrInsertFunction", () => { |
142 | 142 | test("returns a new function if not yet existing in the module", () => { |
143 | 143 | 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 |
148 | 148 | ); |
149 | 149 |
|
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); |
152 | 155 | }); |
153 | 156 |
|
154 | 157 | test("returns the existing function if a function with the given name already exist", () => { |
155 | 158 | const { module, context } = createModule(); |
156 | 159 |
|
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( |
164 | 164 | "sin", |
165 | 165 | llvm.FunctionType.get(llvm.Type.getDoubleTy(context), [], false) |
166 | 166 | ); |
167 | | - expect(queriedFn).toEqual(fun); |
| 167 | + |
| 168 | + expect(functionCallee.callee).toEqual(fun); |
| 169 | + expect(functionCallee.functionType).toEqual(functionType); |
168 | 170 | }); |
169 | 171 | }); |
170 | 172 |
|
@@ -209,22 +211,22 @@ describe("ir/module", () => { |
209 | 211 |
|
210 | 212 | describe("getTypeByName", () => { |
211 | 213 | test("returns null if a type with the given name does not exist", () => { |
212 | | - const {module, context} = createModule(); |
| 214 | + const { module, context } = createModule(); |
213 | 215 |
|
214 | 216 | const type = module.getTypeByName("DoesNotExist"); |
215 | 217 |
|
216 | 218 | expect(type).toBeNull(); |
217 | 219 | }); |
218 | 220 |
|
219 | 221 | 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)]); |
223 | 225 |
|
224 | | - const retrieved = module.getTypeByName("IntTuple"); |
| 226 | + const retrieved = module.getTypeByName("IntTuple"); |
225 | 227 |
|
226 | | - expect(retrieved).toBeInstanceOf(llvm.StructType); |
227 | | - expect(retrieved).toEqual(structType); |
| 228 | + expect(retrieved).toBeInstanceOf(llvm.StructType); |
| 229 | + expect(retrieved).toEqual(structType); |
228 | 230 | }); |
229 | 231 | }); |
230 | 232 | }); |
0 commit comments