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

     1  package constant
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/llir/llvm/ir/types"
     7  )
     8  
     9  // --- [ no_cfi constants ] ----------------------------------------------------
    10  
    11  // NoCFI is an LLVM IR no_cfi constant; a constant representing a function which
    12  // does not get replaced with a reference to the CFI jump table
    13  // (control-flow integrity).
    14  //
    15  // ref: https://llvm.org/docs/LangRef.html#no-cfi
    16  type NoCFI struct {
    17  	// Underlying function.
    18  	Func Constant // *ir.Func
    19  }
    20  
    21  // NewNoCFI returns a new no_cfi constant based on the given function.
    22  func NewNoCFI(f Constant) *NoCFI {
    23  	return &NoCFI{Func: f}
    24  }
    25  
    26  // String returns the LLVM syntax representation of the constant as a type-value
    27  // pair.
    28  func (c *NoCFI) String() string {
    29  	return fmt.Sprintf("%s %s", c.Type(), c.Ident())
    30  }
    31  
    32  // Type returns the type of the constant.
    33  func (c *NoCFI) Type() types.Type {
    34  	return c.Func.Type()
    35  }
    36  
    37  // Ident returns the identifier associated with the constant.
    38  func (c *NoCFI) Ident() string {
    39  	// 'no_cfi' Func=GlobalIdent
    40  	return fmt.Sprintf("no_cfi %s", c.Func.Ident())
    41  }