-
Notifications
You must be signed in to change notification settings - Fork 328
/
device.go
183 lines (171 loc) · 6.83 KB
/
device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package device
import (
"github.com/golang/protobuf/proto"
)
const (
UnknownArchitecture = Architecture_UnknownArchitecture
ARMv7a = Architecture_ARMv7a
ARMv8a = Architecture_ARMv8a
X86 = Architecture_X86
X86_64 = Architecture_X86_64
MIPS = Architecture_MIPS
MIPS64 = Architecture_MIPS64
)
const (
UnknownEndian = Endian_UnknownEndian
BigEndian = Endian_BigEndian
LittleEndian = Endian_LittleEndian
)
const (
UnknownOS = OSKind_UnknownOS
Windows = OSKind_Windows
OSX = OSKind_OSX
Linux = OSKind_Linux
Android = OSKind_Android
)
var (
// ARMv7aLayout is the memory layout for the armv7a ABI.
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.pdf
// 4 DATA TYPES AND ALIGNMENT
ARMv7aLayout = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 4, Alignment: 4},
Integer: &DataTypeLayout{Size: 4, Alignment: 4},
Size: &DataTypeLayout{Size: 4, Alignment: 4},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
// ARM64v8aLayout is the memory layout for the arm64v8a ABI.
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
// 4 DATA TYPES AND ALIGNMENT
ARM64v8aLayout = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 8, Alignment: 8},
Integer: &DataTypeLayout{Size: 8, Alignment: 8},
Size: &DataTypeLayout{Size: 8, Alignment: 8},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
// X86IA32Layout is the memory layout for the x86 IA-32 ABI.
X86IA32Layout = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 4, Alignment: 4},
Integer: &DataTypeLayout{Size: 4, Alignment: 4},
Size: &DataTypeLayout{Size: 4, Alignment: 4},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 4},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 4},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
// X86_64Layout is the memory layout for the x86_64 ABI.
X86_64Layout = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 8, Alignment: 8},
Integer: &DataTypeLayout{Size: 4, Alignment: 4},
Size: &DataTypeLayout{Size: 8, Alignment: 8},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
Little32 = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 4, Alignment: 4},
Integer: &DataTypeLayout{Size: 4, Alignment: 4},
Size: &DataTypeLayout{Size: 4, Alignment: 4},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
Little64 = &MemoryLayout{
Endian: LittleEndian,
Pointer: &DataTypeLayout{Size: 8, Alignment: 8},
Integer: &DataTypeLayout{Size: 8, Alignment: 8},
Size: &DataTypeLayout{Size: 8, Alignment: 8},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
Big32 = &MemoryLayout{
Endian: BigEndian,
Pointer: &DataTypeLayout{Size: 4, Alignment: 4},
Integer: &DataTypeLayout{Size: 4, Alignment: 4},
Size: &DataTypeLayout{Size: 4, Alignment: 4},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
Big64 = &MemoryLayout{
Endian: BigEndian,
Pointer: &DataTypeLayout{Size: 8, Alignment: 8},
Integer: &DataTypeLayout{Size: 8, Alignment: 8},
Size: &DataTypeLayout{Size: 8, Alignment: 8},
Char: &DataTypeLayout{Size: 1, Alignment: 1},
I64: &DataTypeLayout{Size: 8, Alignment: 8},
I32: &DataTypeLayout{Size: 4, Alignment: 4},
I16: &DataTypeLayout{Size: 2, Alignment: 2},
I8: &DataTypeLayout{Size: 1, Alignment: 1},
F64: &DataTypeLayout{Size: 8, Alignment: 8},
F32: &DataTypeLayout{Size: 4, Alignment: 4},
F16: &DataTypeLayout{Size: 2, Alignment: 2},
}
)
// Clone returns a new MemoryLayout copied from m.
func (m *MemoryLayout) Clone() *MemoryLayout {
var out MemoryLayout
bytes, _ := proto.Marshal(m)
proto.Unmarshal(bytes, &out)
return &out
}
// SameAs returns true if the MemoryLayouts are equal.
func (m *MemoryLayout) SameAs(o *MemoryLayout) bool {
return proto.Equal(m, o)
}