@@ -9,6 +9,8 @@ isnull(val::Value) = convert(Core.Bool, API.LLVMIsNull(val))
9
9
10
10
abstract type Constant <: User end
11
11
12
+ unsafe_destroy! (constant:: Constant ) = API. LLVMDestroyConstant (constant)
13
+
12
14
# forward declarations
13
15
@checked mutable struct Module
14
16
ref:: API.LLVMModuleRef
@@ -120,10 +122,14 @@ Base.collect(caz::ConstantAggregateZero) = Value[]
120
122
121
123
# # regular aggregate
122
124
125
+ export ConstantAggregate
126
+
123
127
abstract type ConstantAggregate <: Constant end
124
128
125
129
# arrays
126
130
131
+ export ConstantArray
132
+
127
133
@checked struct ConstantArray <: ConstantAggregate
128
134
ref:: API.LLVMValueRef
129
135
end
202
208
203
209
# structs
204
210
211
+ export ConstantStruct
212
+
205
213
@checked struct ConstantStruct <: ConstantAggregate
206
214
ref:: API.LLVMValueRef
207
215
end
253
261
254
262
# vectors
255
263
264
+ export ConstantVector
265
+
256
266
@checked struct ConstantVector <: ConstantAggregate
257
267
ref:: API.LLVMValueRef
258
268
end
@@ -261,16 +271,208 @@ register(ConstantVector, API.LLVMConstantVectorValueKind)
261
271
262
272
# # constant expressions
263
273
264
- export ConstantExpr, ConstantAggregate, ConstantArray, ConstantStruct, ConstantVector, InlineAsm
274
+ export ConstantExpr,
275
+
276
+ const_neg, const_nswneg, const_nuwneg, const_fneg, const_not, const_add,
277
+ const_nswadd, const_nuwadd, const_fadd, const_sub, const_nswsub, const_nuwsub,
278
+ const_fsub, const_mul, const_nswmul, const_nuwmul, const_fmul, const_udiv,
279
+ const_sdiv, const_fdiv, const_urem, const_srem, const_frem, const_and, const_or,
280
+ const_xor, const_icmp, const_fcmp, const_shl, const_lshr, const_ashr, const_gep,
281
+ const_inbounds_gep, const_trunc, const_sext, const_zext, const_fptrunc, const_fpext,
282
+ const_uitofp, const_sitofp, const_fptoui, const_fptosi, const_ptrtoint,
283
+ const_inttoptr, const_bitcast, const_addrspacecast, const_zextorbitcast,
284
+ const_sextorbitcast, const_truncorbitcast, const_pointercast, const_intcast,
285
+ const_fpcast, const_select, const_extractelement, const_insertelement,
286
+ const_shufflevector, const_extractvalue, const_insertvalue
265
287
266
288
@checked struct ConstantExpr <: Constant
267
289
ref:: API.LLVMValueRef
268
290
end
269
291
register (ConstantExpr, API. LLVMConstantExprValueKind)
270
292
293
+ opcode (ce:: ConstantExpr ) = API. LLVMGetConstOpcode (ce)
294
+
295
+ const_neg (val:: Constant ) =
296
+ Value (API. LLVMConstNeg (val))
297
+
298
+ const_nswneg (val:: Constant ) =
299
+ Value (API. LLVMConstNSWNeg (val))
300
+
301
+ const_nuwneg (val:: Constant ) =
302
+ Value (API. LLVMConstNUWNeg (val))
303
+
304
+ const_fneg (val:: Constant ) =
305
+ Value (API. LLVMConstFNeg (val))
306
+
307
+ const_not (val:: Constant ) =
308
+ Value (API. LLVMConstNot (val))
309
+
310
+ const_add (lhs:: Constant , rhs:: Constant ) =
311
+ Value (API. LLVMConstAdd (lhs, rhs))
312
+
313
+ const_nswadd (lhs:: Constant , rhs:: Constant ) =
314
+ Value (API. LLVMConstNSWAdd (lhs, rhs))
315
+
316
+ const_nuwadd (lhs:: Constant , rhs:: Constant ) =
317
+ Value (API. LLVMConstNUWAdd (lhs, rhs))
318
+
319
+ const_fadd (lhs:: Constant , rhs:: Constant ) =
320
+ Value (API. LLVMConstFAdd (lhs, rhs))
321
+
322
+ const_sub (lhs:: Constant , rhs:: Constant ) =
323
+ Value (API. LLVMConstSub (lhs, rhs))
324
+
325
+ const_nswsub (lhs:: Constant , rhs:: Constant ) =
326
+ Value (API. LLVMConstNSWSub (lhs, rhs))
327
+
328
+ const_nuwsub (lhs:: Constant , rhs:: Constant ) =
329
+ Value (API. LLVMConstNUWSub (lhs, rhs))
330
+
331
+ const_fsub (lhs:: Constant , rhs:: Constant ) =
332
+ Value (API. LLVMConstFSub (lhs, rhs))
333
+
334
+ const_mul (lhs:: Constant , rhs:: Constant ) =
335
+ Value (API. LLVMConstMul (lhs, rhs))
336
+
337
+ const_nswmul (lhs:: Constant , rhs:: Constant ) =
338
+ Value (API. LLVMConstNSWMul (lhs, rhs))
339
+
340
+ const_nuwmul (lhs:: Constant , rhs:: Constant ) =
341
+ Value (API. LLVMConstNUWMul (lhs, rhs))
342
+
343
+ const_fmul (lhs:: Constant , rhs:: Constant ) =
344
+ Value (API. LLVMConstFMul (lhs, rhs))
345
+
346
+ const_udiv (lhs:: Constant , rhs:: Constant ; exact:: Base.Bool = false ) =
347
+ Value (exact ? API. LLVMConstExactUDiv (lhs, rhs) : API. LLVMConstUDiv (lhs, rhs))
348
+
349
+ const_sdiv (lhs:: Constant , rhs:: Constant ; exact:: Base.Bool = false ) =
350
+ Value (exact ? API. LLVMConstExactSDiv (lhs, rhs) : API. LLVMConstSDiv (lhs, rhs))
351
+
352
+ const_fdiv (lhs:: Constant , rhs:: Constant ) =
353
+ Value (API. LLVMConstFDiv (lhs, rhs))
354
+
355
+ const_urem (lhs:: Constant , rhs:: Constant ) =
356
+ Value (API. LLVMConstURem (lhs, rhs))
357
+
358
+ const_srem (lhs:: Constant , rhs:: Constant ) =
359
+ Value (API. LLVMConstSRem (lhs, rhs))
360
+
361
+ const_frem (lhs:: Constant , rhs:: Constant ) =
362
+ Value (API. LLVMConstFRem (lhs, rhs))
363
+
364
+ const_and (lhs:: Constant , rhs:: Constant ) =
365
+ Value (API. LLVMConstAnd (lhs, rhs))
366
+
367
+ const_or (lhs:: Constant , rhs:: Constant ) =
368
+ Value (API. LLVMConstOr (lhs, rhs))
369
+
370
+ const_xor (lhs:: Constant , rhs:: Constant ) =
371
+ Value (API. LLVMConstXor (lhs, rhs))
372
+
373
+ const_icmp (Predicate:: API.LLVMIntPredicate , lhs:: Constant , rhs:: Constant ) =
374
+ Value (API. LLVMConstICmp (Predicate, lhs, rhs))
375
+
376
+ const_fcmp (Predicate:: API.LLVMRealPredicate , lhs:: Constant , rhs:: Constant ) =
377
+ Value (API. LLVMConstFCmp (Predicate, lhs, rhs))
378
+
379
+ const_shl (lhs:: Constant , rhs:: Constant ) =
380
+ Value (API. LLVMConstShl (lhs, rhs))
381
+
382
+ const_lshr (lhs:: Constant , rhs:: Constant ) =
383
+ Value (API. LLVMConstLShr (lhs, rhs))
384
+
385
+ const_ashr (lhs:: Constant , rhs:: Constant ) =
386
+ Value (API. LLVMConstAShr (lhs, rhs))
387
+
388
+ const_gep (val:: Constant , Indices:: Vector{<:Constant} ) =
389
+ Value (API. LLVMConstGEP (val, Indices, length (Indices)))
390
+
391
+ const_inbounds_gep (val:: Constant , Indices:: Vector{<:Constant} ) =
392
+ Value (API. LLVMConstInBoundsGEP (val, Indices, length (indices)))
393
+
394
+ const_trunc (val:: Constant , ToType:: LLVMType ) =
395
+ Value (API. LLVMConstTrunc (val, ToType))
396
+
397
+ const_sext (val:: Constant , ToType:: LLVMType ) =
398
+ Value (API. LLVMConstSExt (val, ToType))
399
+
400
+ const_zext (val:: Constant , ToType:: LLVMType ) =
401
+ Value (API. LLVMConstZExt (val, ToType))
402
+
403
+ const_fptrunc (val:: Constant , ToType:: LLVMType ) =
404
+ Value (API. LLVMConstFPTrunc (val, ToType))
405
+
406
+ const_fpext (val:: Constant , ToType:: LLVMType ) =
407
+ Value (API. LLVMConstFPExt (val, ToType))
408
+
409
+ const_uitofp (val:: Constant , ToType:: LLVMType ) =
410
+ Value (API. LLVMConstUIToFP (val, ToType))
411
+
412
+ const_sitofp (val:: Constant , ToType:: LLVMType ) =
413
+ Value (API. LLVMConstSIToFP (val, ToType))
414
+
415
+ const_fptoui (val:: Constant , ToType:: LLVMType ) =
416
+ Value (API. LLVMConstFPToUI (val, ToType))
417
+
418
+ const_fptosi (val:: Constant , ToType:: LLVMType ) =
419
+ Value (API. LLVMConstFPToSI (val, ToType))
420
+
421
+ const_ptrtoint (val:: Constant , ToType:: LLVMType ) =
422
+ Value (API. LLVMConstPtrToInt (val, ToType))
423
+
424
+ const_inttoptr (val:: Constant , ToType:: LLVMType ) =
425
+ Value (API. LLVMConstIntToPtr (val, ToType))
426
+
427
+ const_bitcast (val:: Constant , ToType:: LLVMType ) =
428
+ Value (API. LLVMConstBitCast (val, ToType))
429
+
430
+ const_addrspacecast (val:: Constant , ToType:: LLVMType ) =
431
+ Value (API. LLVMConstAddrSpaceCast (val, ToType))
432
+
433
+ const_zextorbitcast (val:: Constant , ToType:: LLVMType ) =
434
+ Value (API. LLVMConstZExtOrBitCast (val, ToType))
435
+
436
+ const_sextorbitcast (val:: Constant , ToType:: LLVMType ) =
437
+ Value (API. LLVMConstSExtOrBitCast (val, ToType))
438
+
439
+ const_truncorbitcast (val:: Constant , ToType:: LLVMType ) =
440
+ Value (API. LLVMConstTruncOrBitCast (val, ToType))
441
+
442
+ const_pointercast (val:: Constant , ToType:: LLVMType ) =
443
+ Value (API. LLVMConstPointerCast (val, ToType))
444
+
445
+ const_intcast (val:: Constant , ToType:: LLVMType , isSigned:: Base.Bool ) =
446
+ Value (API. LLVMConstIntCast (val, ToType, isSigned))
447
+
448
+ const_fpcast (val:: Constant , ToType:: LLVMType ) =
449
+ Value (API. LLVMConstFPCast (val, ToType))
450
+
451
+ const_select (cond:: Constant , if_true:: Value , if_false:: Value ) =
452
+ Value (API. LLVMConstSelect (cond, if_true, if_false))
453
+
454
+ const_extractelement (vector:: Constant , index:: Constant ) =
455
+ Value (API. LLVMConstExtractElement (vector ,index))
456
+
457
+ const_insertelement (vector:: Constant , element:: Value , index:: Constant ) =
458
+ Value (API. LLVMConstInsertElement (vector ,element, index))
459
+
460
+ const_shufflevector (vector1:: Constant , vector2:: Constant , mask:: Constant ) =
461
+ Value (API. LLVMConstShuffleVector (vector1, vector2, mask))
462
+
463
+ const_extractvalue (agg:: Constant , Idx:: Vector{<:Integer} ) =
464
+ Value (API. LLVMConstExtractValue (agg, Idx, length (Idx)))
465
+
466
+ const_insertvalue (agg:: Constant , element:: Constant , Idx:: Vector{<:Integer} ) =
467
+ Value (API. LLVMConstInsertValue (agg, element, Idx, length (Idx)))
468
+
469
+ # TODO : alignof, sizeof, block_address
470
+
271
471
272
472
# # inline assembly
273
473
474
+ export InlineAsm
475
+
274
476
@checked struct InlineAsm <: Constant
275
477
ref:: API.LLVMValueRef
276
478
end
0 commit comments