github.com/llir/llvm@v0.3.6/ir/constant/const_blockaddress.go (about) 1 package constant 2 3 import ( 4 "fmt" 5 6 "github.com/llir/llvm/ir/types" 7 "github.com/llir/llvm/ir/value" 8 ) 9 10 // --- [ blockaddress constants ] ---------------------------------------------- 11 12 // BlockAddress is an LLVM IR blockaddress constant. 13 type BlockAddress struct { 14 // Parent function. 15 Func Constant // *ir.Func 16 // Basic block to take address of. 17 Block value.Named // *ir.Block 18 } 19 20 // NewBlockAddress returns a new blockaddress constant based on the given parent 21 // function and basic block. 22 func NewBlockAddress(f Constant, block value.Named) *BlockAddress { 23 return &BlockAddress{Func: f, Block: block} 24 } 25 26 // String returns the LLVM syntax representation of the constant as a type-value 27 // pair. 28 func (c *BlockAddress) 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 *BlockAddress) Type() types.Type { 34 return types.I8Ptr 35 } 36 37 // Ident returns the identifier associated with the constant. 38 func (c *BlockAddress) Ident() string { 39 // 'blockaddress' '(' Func=GlobalIdent ',' Block=LocalIdent ')' 40 return fmt.Sprintf("blockaddress(%s, %s)", c.Func.Ident(), c.Block.Ident()) 41 }