func TestSameLength(t *testing.T) { golden := []struct { a, b types.Type want bool }{ {want: false, a: i32x2VecTyp, b: i32x3VecTyp}, {want: false, a: i32x3VecTyp, b: i32x2VecTyp}, {want: true, a: i32x2VecTyp, b: i32x2VecTyp}, {want: false, a: i32x2ArrTyp, b: i32x3ArrTyp}, {want: false, a: i32x3ArrTyp, b: i32x2ArrTyp}, {want: true, a: i32x2ArrTyp, b: i32x2ArrTyp}, {want: true, a: i32Typ, b: i64Typ}, {want: true, a: i64Typ, b: i32Typ}, {want: false, a: f32Typ, b: i32x2VecTyp}, {want: false, a: i32x2VecTyp, b: f32Typ}, {want: false, a: f32Typ, b: i32x2ArrTyp}, {want: false, a: i32x2ArrTyp, b: f32Typ}, {want: true, a: structTyp, b: f32Typ}, } for i, g := range golden { got := types.SameLength(g.a, g.b) if got != g.want { t.Errorf("i=%d: expected %v, got %v", i, g.want, got) } } }
// NewSIToFP returns a constant expression which converts the signed integer // constant (or constant vector) orig to the corresponding floating point // constant (or constant vector). func NewSIToFP(orig Constant, to types.Type) (*SIToFP, error) { // Verify type of original integer constant (or constant vector). if !types.IsInts(orig.Type()) { return nil, fmt.Errorf("invalid signed integer to floating point conversion; expected integer constant (or constant vector) for orig, got %q", orig.Type()) } // Verify target type. if !types.IsFloats(to) { return nil, fmt.Errorf("invalid signed integer to floating point conversion; expected floating point (or floating point vector) target type, got %q", to) } // Verify that both are either basic types or vectors of the same length. if !types.SameLength(orig.Type(), to) { return nil, fmt.Errorf("invalid signed integer to floating point conversion; cannot convert from %q to %q", orig.Type(), to) } return &SIToFP{orig: orig, to: to}, nil }