本文整理匯總了Golang中github.com/llir/llvm/ir/value.Value.ValueString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.ValueString方法的具體用法?Golang Value.ValueString怎麽用?Golang Value.ValueString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/llir/llvm/ir/value.Value
的用法示例。
在下文中一共展示了Value.ValueString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: convert
// convert converts the given value to the specified type, emitting code to f.
// No conversion is made, if v is already of the correct type.
func (m *Module) convert(f *Function, v value.Value, to irtypes.Type) value.Value {
// Early return if v is already of the correct type.
from := v.Type()
if irtypes.Equal(from, to) {
return v
}
fromType, ok := from.(*irtypes.Int)
if !ok {
panic(fmt.Sprintf("support for converting from type %T not yet implemented", from))
}
toType, ok := to.(*irtypes.Int)
if !ok {
panic(fmt.Sprintf("support for converting to type %T not yet implemented", to))
}
// Convert constant values.
if v, ok := v.(constant.Constant); ok {
switch v := v.(type) {
case *constant.Int:
v, err := constant.NewInt(toType, v.ValueString())
if err != nil {
panic(fmt.Sprintf("unable to create integer constant; %v", err))
}
return v
default:
panic(fmt.Sprintf("support for converting type %T not yet implemented", v))
}
}
// TODO: Add proper support for converting signed and unsigned values, using
// sext and zext, respectively.
// Convert unsigned values.
if irtypes.IsBool(fromType) {
// Zero extend boolean values.
zextInst, err := instruction.NewZExt(v, toType)
if err != nil {
panic(fmt.Sprintf("unable to create sext instruction; %v", err))
}
return f.emitInst(zextInst)
}
// Convert signed values.
if toType.Size() > fromType.Size() {
// Sign extend.
sextInst, err := instruction.NewSExt(v, toType)
if err != nil {
panic(fmt.Sprintf("unable to create sext instruction; %v", err))
}
return f.emitInst(sextInst)
}
// Truncate.
truncInst, err := instruction.NewTrunc(v, toType)
if err != nil {
panic(fmt.Sprintf("unable to create trunc instruction; %v", err))
}
return f.emitInst(truncInst)
}