github.com/llir/llvm@v0.3.6/ir/block_term.go (about)

     1  package ir
     2  
     3  import (
     4  	"github.com/llir/llvm/ir/value"
     5  )
     6  
     7  // --- [ Terminators ] ---------------------------------------------------------
     8  
     9  // ~~~ [ ret ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    10  
    11  // NewRet sets the terminator of the basic block to a new ret terminator based
    12  // on the given return value. A nil return value indicates a void return.
    13  func (block *Block) NewRet(x value.Value) *TermRet {
    14  	term := NewRet(x)
    15  	block.Term = term
    16  	return term
    17  }
    18  
    19  // ~~~ [ br ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    20  
    21  // NewBr sets the terminator of the basic block to a new unconditional br
    22  // terminator based on the given target basic block.
    23  func (block *Block) NewBr(target *Block) *TermBr {
    24  	term := NewBr(target)
    25  	block.Term = term
    26  	return term
    27  }
    28  
    29  // ~~~ [ conditional br ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    30  
    31  // NewCondBr sets the terminator of the basic block to a new conditional br
    32  // terminator based on the given branching condition and conditional target
    33  // basic blocks.
    34  func (block *Block) NewCondBr(cond value.Value, targetTrue, targetFalse *Block) *TermCondBr {
    35  	term := NewCondBr(cond, targetTrue, targetFalse)
    36  	block.Term = term
    37  	return term
    38  }
    39  
    40  // ~~~ [ switch ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    41  
    42  // NewSwitch sets the terminator of the basic block to a new switch terminator
    43  // based on the given control variable, default target basic block and switch
    44  // cases.
    45  func (block *Block) NewSwitch(x value.Value, targetDefault *Block, cases ...*Case) *TermSwitch {
    46  	term := NewSwitch(x, targetDefault, cases...)
    47  	block.Term = term
    48  	return term
    49  }
    50  
    51  // ~~~ [ indirectbr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    52  
    53  // NewIndirectBr sets the terminator of the basic block to a new indirectbr
    54  // terminator based on the given target address (derived from a blockaddress
    55  // constant of type i8*) and set of valid target basic blocks.
    56  func (block *Block) NewIndirectBr(addr value.Value, validTargets ...*Block) *TermIndirectBr {
    57  	term := NewIndirectBr(addr, validTargets...)
    58  	block.Term = term
    59  	return term
    60  }
    61  
    62  // ~~~ [ invoke ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    63  
    64  // NewInvoke sets the terminator of the basic block to a new invoke terminator
    65  // based on the given invokee, function arguments and control flow return points
    66  // for normal and exceptional execution.
    67  //
    68  // TODO: specify the set of underlying types of invokee.
    69  func (block *Block) NewInvoke(invokee value.Value, args []value.Value, normalRetTarget, exceptionRetTarget *Block) *TermInvoke {
    70  	term := NewInvoke(invokee, args, normalRetTarget, exceptionRetTarget)
    71  	block.Term = term
    72  	return term
    73  }
    74  
    75  // ~~~ [ callbr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    76  
    77  // NewCallBr sets the terminator of the basic block to a new callbr terminator
    78  // based on the given callee, function arguments and control flow return points
    79  // for normal and exceptional execution.
    80  //
    81  // TODO: specify the set of underlying types of callee.
    82  func (block *Block) NewCallBr(callee value.Value, args []value.Value, normalRetTarget *Block, otherRetTargets ...*Block) *TermCallBr {
    83  	term := NewCallBr(callee, args, normalRetTarget, otherRetTargets...)
    84  	block.Term = term
    85  	return term
    86  }
    87  
    88  // ~~~ [ resume ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    89  
    90  // NewResume sets the terminator of the basic block to a new resume terminator
    91  // based on the given exception argument to propagate.
    92  func (block *Block) NewResume(x value.Value) *TermResume {
    93  	term := NewResume(x)
    94  	block.Term = term
    95  	return term
    96  }
    97  
    98  // ~~~ [ catchswitch ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    99  
   100  // NewCatchSwitch sets the terminator of the basic block to a new catchswitch
   101  // terminator based on the given parent exception pad, exception handlers and
   102  // optional default unwind target. If defaultUnwindTarget is nil, catchswitch
   103  // unwinds to caller function.
   104  func (block *Block) NewCatchSwitch(parentPad ExceptionPad, handlers []*Block, defaultUnwindTarget *Block) *TermCatchSwitch {
   105  	term := NewCatchSwitch(parentPad, handlers, defaultUnwindTarget)
   106  	block.Term = term
   107  	return term
   108  }
   109  
   110  // ~~~ [ catchret ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   111  
   112  // NewCatchRet sets the terminator of the basic block to a new catchret
   113  // terminator based on the given exit catchpad and target basic block.
   114  func (block *Block) NewCatchRet(catchPad *InstCatchPad, target *Block) *TermCatchRet {
   115  	term := NewCatchRet(catchPad, target)
   116  	block.Term = term
   117  	return term
   118  }
   119  
   120  // ~~~ [ cleanupret ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   121  
   122  // NewCleanupRet sets the terminator of the basic block to a new cleanupret
   123  // terminator based on the given exit cleanuppad and optional unwind target. If
   124  // unwindTarget is nil, cleanupret unwinds to caller function.
   125  func (block *Block) NewCleanupRet(cleanupPad *InstCleanupPad, unwindTarget *Block) *TermCleanupRet {
   126  	term := NewCleanupRet(cleanupPad, unwindTarget)
   127  	block.Term = term
   128  	return term
   129  }
   130  
   131  // ~~~ [ unreachable ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   132  
   133  // NewUnreachable sets the terminator of the basic block to a new unreachable
   134  // terminator.
   135  func (block *Block) NewUnreachable() *TermUnreachable {
   136  	term := NewUnreachable()
   137  	block.Term = term
   138  	return term
   139  }