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

     1  // Package constant implements values representing immutable LLVM IR constants.
     2  package constant
     3  
     4  import (
     5  	"github.com/llir/llvm/ir/types"
     6  	"github.com/llir/llvm/ir/value"
     7  )
     8  
     9  // === [ Constants ] ===========================================================
    10  
    11  // Convenience constants.
    12  var (
    13  	// None token constant.
    14  	None = &NoneToken{} // none
    15  	// Boolean constants.
    16  	True  = NewInt(types.I1, 1) // true
    17  	False = NewInt(types.I1, 0) // false
    18  )
    19  
    20  // Constant is an LLVM IR constant; a value that is immutable at runtime, such
    21  // as an integer or floating-point literal, or the address of a function or
    22  // global variable.
    23  //
    24  // A Constant has one of the following underlying types.
    25  //
    26  // Simple constants
    27  //
    28  // https://llvm.org/docs/LangRef.html#simple-constants
    29  //
    30  //    *constant.Int         // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Int
    31  //    *constant.Float       // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Float
    32  //    *constant.Null        // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Null
    33  //    *constant.NoneToken   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#NoneToken
    34  //
    35  // Complex constants
    36  //
    37  // https://llvm.org/docs/LangRef.html#complex-constants
    38  //
    39  //    *constant.Struct            // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Struct
    40  //    *constant.Array             // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Array
    41  //    *constant.CharArray         // https://pkg.go.dev/github.com/llir/llvm/ir/constant#CharArray
    42  //    *constant.Vector            // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Vector
    43  //    *constant.ZeroInitializer   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#ZeroInitializer
    44  //    TODO: include metadata node?
    45  //
    46  // Global variable and function addresses
    47  //
    48  // https://llvm.org/docs/LangRef.html#global-variable-and-function-addresses
    49  //
    50  //    *ir.Global   // https://pkg.go.dev/github.com/llir/llvm/ir#Global
    51  //    *ir.Func     // https://pkg.go.dev/github.com/llir/llvm/ir#Func
    52  //    *ir.Alias    // https://pkg.go.dev/github.com/llir/llvm/ir#Alias
    53  //    *ir.IFunc    // https://pkg.go.dev/github.com/llir/llvm/ir#IFunc
    54  //
    55  // Undefined values
    56  //
    57  // https://llvm.org/docs/LangRef.html#undefined-values
    58  //
    59  //    *constant.Undef   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Undef
    60  //
    61  // Poison values
    62  //
    63  // https://llvm.org/docs/LangRef.html#poison-values
    64  //
    65  //    *constant.Poison   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Poison
    66  //
    67  // Addresses of basic blocks
    68  //
    69  // https://llvm.org/docs/LangRef.html#addresses-of-basic-blocks
    70  //
    71  //    *constant.BlockAddress   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#BlockAddress
    72  //
    73  // Constant expressions
    74  //
    75  // https://llvm.org/docs/LangRef.html#constant-expressions
    76  //
    77  //    constant.Expression   // https://pkg.go.dev/github.com/llir/llvm/ir/constant#Expression
    78  type Constant interface {
    79  	value.Value
    80  	// IsConstant ensures that only constants can be assigned to the
    81  	// constant.Constant interface.
    82  	IsConstant()
    83  }