@@ -195,6 +195,15 @@ const (
195195 ShuffleVector Opcode = C .LLVMShuffleVector
196196 ExtractValue Opcode = C .LLVMExtractValue
197197 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
198207)
199208
200209const (
@@ -934,7 +943,7 @@ func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
934943 return
935944}
936945
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 }
938947
939948func ConstGEP (t Type , v Value , indices []Value ) (rv Value ) {
940949 ptr , nvals := llvmValueRefs (indices )
@@ -1401,12 +1410,87 @@ func (b Builder) CreateInvoke(t Type, fn Value, args []Value, then, catch BasicB
14011410}
14021411func (b Builder ) CreateUnreachable () (rv Value ) { rv .C = C .LLVMBuildUnreachable (b .C ); return }
14031412
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+
14041459// Add a case to the switch instruction
14051460func (v Value ) AddCase (on Value , dest BasicBlock ) { C .LLVMAddCase (v .C , on .C , dest .C ) }
14061461
14071462// Add a destination to the indirectbr instruction
14081463func (v Value ) AddDest (dest BasicBlock ) { C .LLVMAddDestination (v .C , dest .C ) }
14091464
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+
14101494// Arithmetic
14111495func (b Builder ) CreateAdd (lhs , rhs Value , name string ) (v Value ) {
14121496 cname := C .CString (name )
@@ -1888,13 +1972,6 @@ func (b Builder) CreatePtrDiff(t Type, lhs, rhs Value, name string) (v Value) {
18881972 return
18891973}
18901974
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-
18981975func (l Value ) AddClause (v Value ) {
18991976 C .LLVMAddClause (l .C , v .C )
19001977}
@@ -1903,11 +1980,6 @@ func (l Value) SetCleanup(cleanup bool) {
19031980 C .LLVMSetCleanup (l .C , boolToLLVMBool (cleanup ))
19041981}
19051982
1906- func (b Builder ) CreateResume (ex Value ) (v Value ) {
1907- v .C = C .LLVMBuildResume (b .C , ex .C )
1908- return
1909- }
1910-
19111983//-------------------------------------------------------------------------
19121984// llvm.ModuleProvider
19131985//-------------------------------------------------------------------------
0 commit comments