@@ -195,6 +195,15 @@ const (
195
195
ShuffleVector Opcode = C .LLVMShuffleVector
196
196
ExtractValue Opcode = C .LLVMExtractValue
197
197
InsertValue Opcode = C .LLVMInsertValue
198
+
199
+ // Exception Handling Operators
200
+ Resume Opcode = C .LLVMResume
201
+ LandingPad Opcode = C .LLVMLandingPad
202
+ CleanupRet Opcode = C .LLVMCleanupRet
203
+ CatchRet Opcode = C .LLVMCatchRet
204
+ CatchPad Opcode = C .LLVMCatchPad
205
+ CleanupPad Opcode = C .LLVMCleanupPad
206
+ CatchSwitch Opcode = C .LLVMCatchSwitch
198
207
)
199
208
200
209
const (
@@ -934,7 +943,7 @@ func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
934
943
return
935
944
}
936
945
937
- func ConstShl (lhs , rhs Value ) (v Value ) { v .C = C .LLVMConstShl (lhs .C , rhs .C ); return }
946
+ func ConstShl (lhs , rhs Value ) (v Value ) { v .C = C .LLVMConstShl (lhs .C , rhs .C ); return }
938
947
939
948
func ConstGEP (t Type , v Value , indices []Value ) (rv Value ) {
940
949
ptr , nvals := llvmValueRefs (indices )
@@ -1401,12 +1410,87 @@ func (b Builder) CreateInvoke(t Type, fn Value, args []Value, then, catch BasicB
1401
1410
}
1402
1411
func (b Builder ) CreateUnreachable () (rv Value ) { rv .C = C .LLVMBuildUnreachable (b .C ); return }
1403
1412
1413
+ // Exception Handling
1414
+
1415
+ func (b Builder ) CreateResume (ex Value ) (v Value ) {
1416
+ v .C = C .LLVMBuildResume (b .C , ex .C )
1417
+ return
1418
+ }
1419
+
1420
+ func (b Builder ) CreateLandingPad (t Type , nclauses int , name string ) (l Value ) {
1421
+ cname := C .CString (name )
1422
+ defer C .free (unsafe .Pointer (cname ))
1423
+ l .C = C .LLVMBuildLandingPad (b .C , t .C , nil , C .unsigned (nclauses ), cname )
1424
+ return l
1425
+ }
1426
+
1427
+ func (b Builder ) CreateCleanupRet (catchpad Value , bb BasicBlock ) (v Value ) {
1428
+ v .C = C .LLVMBuildCleanupRet (b .C , catchpad .C , bb .C )
1429
+ return
1430
+ }
1431
+
1432
+ func (b Builder ) CreateCatchRet (catchpad Value , bb BasicBlock ) (v Value ) {
1433
+ v .C = C .LLVMBuildCatchRet (b .C , catchpad .C , bb .C )
1434
+ return
1435
+ }
1436
+
1437
+ func (b Builder ) CreateCatchPad (parentPad Value , args []Value , name string ) (v Value ) {
1438
+ cname := C .CString (name )
1439
+ defer C .free (unsafe .Pointer (cname ))
1440
+ ptr , nvals := llvmValueRefs (args )
1441
+ v .C = C .LLVMBuildCatchPad (b .C , parentPad .C , ptr , nvals , cname )
1442
+ return
1443
+ }
1444
+
1445
+ func (b Builder ) CreateCleanupPad (parentPad Value , args []Value , name string ) (v Value ) {
1446
+ cname := C .CString (name )
1447
+ defer C .free (unsafe .Pointer (cname ))
1448
+ ptr , nvals := llvmValueRefs (args )
1449
+ v .C = C .LLVMBuildCleanupPad (b .C , parentPad .C , ptr , nvals , cname )
1450
+ return
1451
+ }
1452
+ func (b Builder ) CreateCatchSwitch (parentPad Value , unwindBB BasicBlock , numHandlers int , name string ) (v Value ) {
1453
+ cname := C .CString (name )
1454
+ defer C .free (unsafe .Pointer (cname ))
1455
+ v .C = C .LLVMBuildCatchSwitch (b .C , parentPad .C , unwindBB .C , C .unsigned (numHandlers ), cname )
1456
+ return
1457
+ }
1458
+
1404
1459
// Add a case to the switch instruction
1405
1460
func (v Value ) AddCase (on Value , dest BasicBlock ) { C .LLVMAddCase (v .C , on .C , dest .C ) }
1406
1461
1407
1462
// Add a destination to the indirectbr instruction
1408
1463
func (v Value ) AddDest (dest BasicBlock ) { C .LLVMAddDestination (v .C , dest .C ) }
1409
1464
1465
+ // Add a destination to the catchswitch instruction.
1466
+ func (v Value ) AddHandler (bb BasicBlock ) { C .LLVMAddHandler (v .C , bb .C ) }
1467
+
1468
+ // Obtain the basic blocks acting as handlers for a catchswitch instruction.
1469
+ func (v Value ) GetHandlers () []BasicBlock {
1470
+ num := C .LLVMGetNumHandlers (v .C )
1471
+ if num == 0 {
1472
+ return nil
1473
+ }
1474
+ blocks := make ([]BasicBlock , num )
1475
+ C .LLVMGetHandlers (v .C , & blocks [0 ].C )
1476
+ return blocks
1477
+ }
1478
+
1479
+ // Get the parent catchswitch instruction of a catchpad instruction.
1480
+ //
1481
+ // This only works on catchpad instructions.
1482
+ func (v Value ) GetParentCatchSwitch () (rv Value ) {
1483
+ rv .C = C .LLVMGetParentCatchSwitch (v .C )
1484
+ return
1485
+ }
1486
+
1487
+ // Set the parent catchswitch instruction of a catchpad instruction.
1488
+ //
1489
+ // This only works on llvm::CatchPadInst instructions.
1490
+ func (v Value ) SetParentCatchSwitch (catchSwitch Value ) {
1491
+ C .LLVMSetParentCatchSwitch (v .C , catchSwitch .C )
1492
+ }
1493
+
1410
1494
// Arithmetic
1411
1495
func (b Builder ) CreateAdd (lhs , rhs Value , name string ) (v Value ) {
1412
1496
cname := C .CString (name )
@@ -1888,13 +1972,6 @@ func (b Builder) CreatePtrDiff(t Type, lhs, rhs Value, name string) (v Value) {
1888
1972
return
1889
1973
}
1890
1974
1891
- func (b Builder ) CreateLandingPad (t Type , nclauses int , name string ) (l Value ) {
1892
- cname := C .CString (name )
1893
- defer C .free (unsafe .Pointer (cname ))
1894
- l .C = C .LLVMBuildLandingPad (b .C , t .C , nil , C .unsigned (nclauses ), cname )
1895
- return l
1896
- }
1897
-
1898
1975
func (l Value ) AddClause (v Value ) {
1899
1976
C .LLVMAddClause (l .C , v .C )
1900
1977
}
@@ -1903,11 +1980,6 @@ func (l Value) SetCleanup(cleanup bool) {
1903
1980
C .LLVMSetCleanup (l .C , boolToLLVMBool (cleanup ))
1904
1981
}
1905
1982
1906
- func (b Builder ) CreateResume (ex Value ) (v Value ) {
1907
- v .C = C .LLVMBuildResume (b .C , ex .C )
1908
- return
1909
- }
1910
-
1911
1983
//-------------------------------------------------------------------------
1912
1984
// llvm.ModuleProvider
1913
1985
//-------------------------------------------------------------------------
0 commit comments