Debian Codegraph @

internal/engine/wazevo/ssa/type.go

raw
1 package ssa
2
3 type Type byte
4
5 const (
6 typeInvalid Type = iota
7
8 // TODO: add 8, 16 bit types when it's needed for optimizations.
9
10 // TypeI32 represents an integer type with 32 bits.
11 TypeI32
12
13 // TypeI64 represents an integer type with 64 bits.
14 TypeI64
15
16 // TypeF32 represents 32-bit floats in the IEEE 754.
17 TypeF32
18
19 // TypeF64 represents 64-bit floats in the IEEE 754.
20 TypeF64
21
22 // TypeV128 represents 128-bit SIMD vectors.
23 TypeV128
24
25 // -- Do not add new types after this line. ----
26 typeEnd
27 )
28
29 // String implements fmt.Stringer.
30 func (t Type) String() (ret string) {
31 switch t {
32 case typeInvalid:
33 return "invalid"
34 case TypeI32:
35 return "i32"
36 case TypeI64:
37 return "i64"
38 case TypeF32:
39 return "f32"
40 case TypeF64:
41 return "f64"
42 case TypeV128:
43 return "v128"
44 default:
45 panic(int(t))
46 }
47 }
48
49 // IsInt returns true if the type is an integer type.
50 func (t Type) IsInt() bool {
51 return t == TypeI32 || t == TypeI64
52 }
53
54 // IsFloat returns true if the type is a floating point type.
55 func (t Type) IsFloat() bool {
56 return t == TypeF32 || t == TypeF64
57 }
58
59 // Bits returns the number of bits required to represent the type.
60 func (t Type) Bits() byte {
61 switch t {
62 case TypeI32, TypeF32:
63 return 32
64 case TypeI64, TypeF64:
65 return 64
66 case TypeV128:
67 return 128
68 default:
69 panic(int(t))
70 }
71 }
72
73 // Size returns the number of bytes required to represent the type.
74 func (t Type) Size() byte {
75 return t.Bits() / 8
76 }
77
78 func (t Type) invalid() bool {
79 return t == typeInvalid
80 }
81
82 // VecLane represents a lane in a SIMD vector.
83 type VecLane byte
84
85 const (
86 VecLaneInvalid VecLane = 1 + iota
87 VecLaneI8x16
88 VecLaneI16x8
89 VecLaneI32x4
90 VecLaneI64x2
91 VecLaneF32x4
92 VecLaneF64x2
93 )
94
95 // String implements fmt.Stringer.
96 func (vl VecLane) String() (ret string) {
97 switch vl {
98 case VecLaneInvalid:
99 return "invalid"
100 case VecLaneI8x16:
101 return "i8x16"
102 case VecLaneI16x8:
103 return "i16x8"
104 case VecLaneI32x4:
105 return "i32x4"
106 case VecLaneI64x2:
107 return "i64x2"
108 case VecLaneF32x4:
109 return "f32x4"
110 case VecLaneF64x2:
111 return "f64x2"
112 default:
113 panic(int(vl))
114 }
115 }