@@ -6,6 +6,7 @@ use std::{
6
6
os:: unix:: io:: * ,
7
7
path:: * ,
8
8
process:: { Command , Stdio } ,
9
+ str:: FromStr ,
9
10
} ;
10
11
use walkdir:: WalkDir ;
11
12
@@ -116,6 +117,116 @@ pub enum Target {
116
117
Z14 ,
117
118
}
118
119
120
+ impl FromStr for Target {
121
+ type Err = Error ;
122
+
123
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
124
+ let target = match s. to_ascii_lowercase ( ) . as_str ( ) {
125
+ // X86/X86_64 Intel
126
+ "p2" => Self :: P2 ,
127
+ "katamai" => Self :: KATMAI ,
128
+ "coppermine" => Self :: COPPERMINE ,
129
+ "northwood" => Self :: NORTHWOOD ,
130
+ "prescott" => Self :: PRESCOTT ,
131
+ "banias" => Self :: BANIAS ,
132
+ "yonah" => Self :: YONAH ,
133
+ "core2" => Self :: CORE2 ,
134
+ "penryn" => Self :: PENRYN ,
135
+ "dunnington" => Self :: DUNNINGTON ,
136
+ "nehalem" => Self :: NEHALEM ,
137
+ "sandybridge" => Self :: SANDYBRIDGE ,
138
+ "haswell" => Self :: HASWELL ,
139
+ "skylakex" => Self :: SKYLAKEX ,
140
+ "atom" => Self :: ATOM ,
141
+
142
+ // X86/X86_64 AMD
143
+ "athlon" => Self :: ATHLON ,
144
+ "opteron" => Self :: OPTERON ,
145
+ "opteron_sse3" => Self :: OPTERON_SSE3 ,
146
+ "barcelona" => Self :: BARCELONA ,
147
+ "shanghai" => Self :: SHANGHAI ,
148
+ "istanbul" => Self :: ISTANBUL ,
149
+ "bobcat" => Self :: BOBCAT ,
150
+ "bulldozer" => Self :: BULLDOZER ,
151
+ "piledriver" => Self :: PILEDRIVER ,
152
+ "steamroller" => Self :: STEAMROLLER ,
153
+ "excavator" => Self :: EXCAVATOR ,
154
+ "zen" => Self :: ZEN ,
155
+
156
+ // X86/X86_64 generic
157
+ "sse_generic" => Self :: SSE_GENERIC ,
158
+ "viac3" => Self :: VIAC3 ,
159
+ "nano" => Self :: NANO ,
160
+
161
+ // Power
162
+ "power4" => Self :: POWER4 ,
163
+ "power5" => Self :: POWER5 ,
164
+ "power6" => Self :: POWER6 ,
165
+ "power7" => Self :: POWER7 ,
166
+ "power8" => Self :: POWER8 ,
167
+ "power9" => Self :: POWER9 ,
168
+ "ppcg4" => Self :: PPCG4 ,
169
+ "ppc970" => Self :: PPC970 ,
170
+ "ppc970mp" => Self :: PPC970MP ,
171
+ "ppc440" => Self :: PPC440 ,
172
+ "ppc440fp2" => Self :: PPC440FP2 ,
173
+ "cell" => Self :: CELL ,
174
+
175
+ // MIPS
176
+ "p5600" => Self :: P5600 ,
177
+ "mips1004k" => Self :: MIPS1004K ,
178
+ "mips24k" => Self :: MIPS24K ,
179
+
180
+ // MIPS64
181
+ "sicortex" => Self :: SICORTEX ,
182
+ "loongson3a" => Self :: LOONGSON3A ,
183
+ "loongson3b" => Self :: LOONGSON3B ,
184
+ "i6400" => Self :: I6400 ,
185
+ "p6600" => Self :: P6600 ,
186
+ "i6500" => Self :: I6500 ,
187
+
188
+ // IA64
189
+ "itanium2" => Self :: ITANIUM2 ,
190
+
191
+ // Sparc
192
+ "sparc" => Self :: SPARC ,
193
+ "sparcv7" => Self :: SPARCV7 ,
194
+
195
+ // ARM
196
+ "cortexa15" => Self :: CORTEXA15 ,
197
+ "cortexa9" => Self :: CORTEXA9 ,
198
+ "armv7" => Self :: ARMV7 ,
199
+ "armv6" => Self :: ARMV6 ,
200
+ "armv5" => Self :: ARMV5 ,
201
+
202
+ // ARM64
203
+ "armv8" => Self :: ARMV8 ,
204
+ "cortexa53" => Self :: CORTEXA53 ,
205
+ "cortexa57" => Self :: CORTEXA57 ,
206
+ "cortexa72" => Self :: CORTEXA72 ,
207
+ "cortexa73" => Self :: CORTEXA73 ,
208
+ "neoversen1" => Self :: NEOVERSEN1 ,
209
+ "emag8180" => Self :: EMAG8180 ,
210
+ "falkor" => Self :: FALKOR ,
211
+ "thunderx" => Self :: THUNDERX ,
212
+ "thunderx2t99" => Self :: THUNDERX2T99 ,
213
+ "tsv110" => Self :: TSV110 ,
214
+
215
+ // System Z
216
+ "zarch_generic" => Self :: ZARCH_GENERIC ,
217
+ "z13" => Self :: Z13 ,
218
+ "z14" => Self :: Z14 ,
219
+
220
+ _ => {
221
+ return Err ( Error :: UnsupportedTarget {
222
+ target : s. to_string ( ) ,
223
+ } )
224
+ }
225
+ } ;
226
+ Ok ( target)
227
+ }
228
+ }
229
+
119
230
/// make option generator
120
231
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
121
232
pub struct Configure {
@@ -314,6 +425,15 @@ impl Configure {
314
425
mod tests {
315
426
use super :: * ;
316
427
428
+ #[ test]
429
+ fn target_from_str ( ) {
430
+ assert_eq ! ( Target :: from_str( "p2" ) . unwrap( ) , Target :: P2 ) ;
431
+ assert ! ( matches!(
432
+ Target :: from_str( "p3" ) . unwrap_err( ) ,
433
+ crate :: error:: Error :: UnsupportedTarget { .. }
434
+ ) ) ;
435
+ }
436
+
317
437
#[ ignore]
318
438
#[ test]
319
439
fn build_default ( ) {
0 commit comments