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

     1  package constant
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/llir/llvm/ir/types"
     7  )
     8  
     9  // --- [ Unary expressions ] ---------------------------------------------------
    10  
    11  // ~~~ [ fneg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12  
    13  // ExprFNeg is an LLVM IR fneg expression.
    14  type ExprFNeg struct {
    15  	// Operand.
    16  	X Constant // floating-point scalar or vector constant
    17  
    18  	// extra.
    19  
    20  	// Type of result produced by the constant expression.
    21  	Typ types.Type
    22  }
    23  
    24  // NewFNeg returns a new fneg expression based on the given operand.
    25  func NewFNeg(x Constant) *ExprFNeg {
    26  	e := &ExprFNeg{X: x}
    27  	// Compute type.
    28  	e.Type()
    29  	return e
    30  }
    31  
    32  // String returns the LLVM syntax representation of the constant expression as a
    33  // type-value pair.
    34  func (e *ExprFNeg) String() string {
    35  	return fmt.Sprintf("%s %s", e.Type(), e.Ident())
    36  }
    37  
    38  // Type returns the type of the constant expression.
    39  func (e *ExprFNeg) Type() types.Type {
    40  	// Cache type if not present.
    41  	if e.Typ == nil {
    42  		e.Typ = e.X.Type()
    43  	}
    44  	return e.Typ
    45  }
    46  
    47  // Ident returns the identifier associated with the constant expression.
    48  func (e *ExprFNeg) Ident() string {
    49  	// 'fneg' '(' X=TypeConst ')'
    50  	return fmt.Sprintf("fneg (%s)", e.X)
    51  }