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

     1  package ir
     2  
     3  import (
     4  	"github.com/llir/llvm/ir/enum"
     5  	"github.com/llir/llvm/ir/types"
     6  	"github.com/llir/llvm/ir/value"
     7  )
     8  
     9  // --- [ Other instructions ] --------------------------------------------------
    10  
    11  // ~~~ [ icmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12  
    13  // NewICmp appends a new icmp instruction to the basic block based on the given
    14  // integer comparison predicate and integer scalar or vector operands.
    15  func (block *Block) NewICmp(pred enum.IPred, x, y value.Value) *InstICmp {
    16  	inst := NewICmp(pred, x, y)
    17  	block.Insts = append(block.Insts, inst)
    18  	return inst
    19  }
    20  
    21  // ~~~ [ fcmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    22  
    23  // NewFCmp appends a new fcmp instruction to the basic block based on the given
    24  // floating-point comparison predicate and floating-point scalar or vector
    25  // operands.
    26  func (block *Block) NewFCmp(pred enum.FPred, x, y value.Value) *InstFCmp {
    27  	inst := NewFCmp(pred, x, y)
    28  	block.Insts = append(block.Insts, inst)
    29  	return inst
    30  }
    31  
    32  // ~~~ [ phi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    33  
    34  // NewPhi appends a new phi instruction to the basic block based on the given
    35  // incoming values.
    36  func (block *Block) NewPhi(incs ...*Incoming) *InstPhi {
    37  	inst := NewPhi(incs...)
    38  	block.Insts = append(block.Insts, inst)
    39  	return inst
    40  }
    41  
    42  // ~~~ [ select ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    43  
    44  // NewSelect appends a new select instruction to the basic block based on the
    45  // given selection condition and true and false condition values.
    46  func (block *Block) NewSelect(cond, valueTrue, valueFalse value.Value) *InstSelect {
    47  	inst := NewSelect(cond, valueTrue, valueFalse)
    48  	block.Insts = append(block.Insts, inst)
    49  	return inst
    50  }
    51  
    52  // ~~~ [ call ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    53  
    54  // NewCall appends a new call instruction to the basic block based on the given
    55  // callee and function arguments.
    56  //
    57  // TODO: specify the set of underlying types of callee.
    58  func (block *Block) NewCall(callee value.Value, args ...value.Value) *InstCall {
    59  	inst := NewCall(callee, args...)
    60  	block.Insts = append(block.Insts, inst)
    61  	return inst
    62  }
    63  
    64  // ~~~ [ va_arg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    65  
    66  // NewVAArg appends a new va_arg instruction to the basic block based on the
    67  // given variable argument list and argument type.
    68  func (block *Block) NewVAArg(vaList value.Value, argType types.Type) *InstVAArg {
    69  	inst := NewVAArg(vaList, argType)
    70  	block.Insts = append(block.Insts, inst)
    71  	return inst
    72  }
    73  
    74  // ~~~ [ landingpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    75  
    76  // NewLandingPad appends a new landingpad instruction to the basic block based
    77  // on the given result type and filter/catch clauses.
    78  func (block *Block) NewLandingPad(resultType types.Type, clauses ...*Clause) *InstLandingPad {
    79  	inst := NewLandingPad(resultType, clauses...)
    80  	block.Insts = append(block.Insts, inst)
    81  	return inst
    82  }
    83  
    84  // ~~~ [ catchpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    85  
    86  // NewCatchPad appends a new catchpad instruction to the basic block based on
    87  // the given parent catchswitch terminator and exception arguments.
    88  func (block *Block) NewCatchPad(catchSwitch *TermCatchSwitch, args ...value.Value) *InstCatchPad {
    89  	inst := NewCatchPad(catchSwitch, args...)
    90  	block.Insts = append(block.Insts, inst)
    91  	return inst
    92  }
    93  
    94  // ~~~ [ cleanuppad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    95  
    96  // NewCleanupPad appends a new cleanuppad instruction to the basic block based
    97  // on the given parent exception pad and exception arguments.
    98  func (block *Block) NewCleanupPad(parentPad ExceptionPad, args ...value.Value) *InstCleanupPad {
    99  	inst := NewCleanupPad(parentPad, args...)
   100  	block.Insts = append(block.Insts, inst)
   101  	return inst
   102  }