github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/value.go (about) 1 package ccall 2 3 /* 4 #cgo CFLAGS: -I../ 5 #cgo CFLAGS: -Iinclude 6 7 #include <jit/jit.h> 8 */ 9 import "C" 10 import ( 11 "reflect" 12 "unsafe" 13 ) 14 15 type Value struct { 16 c C.jit_value_t 17 } 18 19 type Values []*Value 20 21 func (v Values) c() *C.jit_value_t { 22 cvalues := make([]C.jit_value_t, len(v)) 23 for idx, vv := range v { 24 cvalues[idx] = vv.c 25 } 26 return (*C.jit_value_t)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&cvalues)).Data)) 27 } 28 29 func toValue(c C.jit_value_t) *Value { 30 return &Value{c} 31 } 32 33 func (v *Value) IsTemporary() bool { 34 return int(C.jit_value_is_temporary(v.c)) == 1 35 } 36 37 func (v *Value) IsLocal() bool { 38 return int(C.jit_value_is_local(v.c)) == 1 39 } 40 41 func (v *Value) IsConstant() bool { 42 return int(C.jit_value_is_constant(v.c)) == 1 43 } 44 45 func (v *Value) IsParameter() bool { 46 return int(C.jit_value_is_parameter(v.c)) == 1 47 } 48 49 func (v *Value) SetVolatile() { 50 C.jit_value_set_volatile(v.c) 51 } 52 53 func (v *Value) IsVolatile() bool { 54 return int(C.jit_value_is_volatile(v.c)) == 1 55 } 56 57 func (v *Value) SetAddressable() { 58 C.jit_value_set_addressable(v.c) 59 } 60 61 func (v *Value) IsAddressable() bool { 62 return int(C.jit_value_is_addressable(v.c)) == 1 63 } 64 65 func (v *Value) Type() *Type { 66 return toType(C.jit_value_get_type(v.c)) 67 } 68 69 func (v *Value) Function() *Function { 70 return toFunction(C.jit_value_get_function(v.c)) 71 } 72 73 func (v *Value) Block() *Block { 74 return toBlock(C.jit_value_get_block(v.c)) 75 } 76 77 func (v *Value) Context() *Context { 78 return toContext(C.jit_value_get_context(v.c)) 79 } 80 81 //func (v *Value) Constant() *Constant { 82 // return toConstant(C.jit_value_get_constant(v.c)) 83 //} 84 85 func (v *Value) Int() int { 86 return int(C.jit_value_get_nint_constant(v.c)) 87 } 88 89 func (v *Value) Long() int64 { 90 return int64(C.jit_value_get_long_constant(v.c)) 91 } 92 93 func (v *Value) Float32() float32 { 94 return float32(C.jit_value_get_float32_constant(v.c)) 95 } 96 97 func (v *Value) Float64() float64 { 98 return float64(C.jit_value_get_float64_constant(v.c)) 99 } 100 101 func (v *Value) IsTrue() bool { 102 return int(C.jit_value_is_true(v.c)) == 1 103 }