@@ -305,6 +305,43 @@ impl ToJson for RelocModel {
305
305
}
306
306
}
307
307
308
+ #[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
309
+ pub enum CodeModel {
310
+ Tiny ,
311
+ Small ,
312
+ Kernel ,
313
+ Medium ,
314
+ Large ,
315
+ }
316
+
317
+ impl FromStr for CodeModel {
318
+ type Err = ( ) ;
319
+
320
+ fn from_str ( s : & str ) -> Result < CodeModel , ( ) > {
321
+ Ok ( match s {
322
+ // "tiny" => CodeModel::Tiny, // Not exposed to users right now.
323
+ "small" => CodeModel :: Small ,
324
+ "kernel" => CodeModel :: Kernel ,
325
+ "medium" => CodeModel :: Medium ,
326
+ "large" => CodeModel :: Large ,
327
+ _ => return Err ( ( ) ) ,
328
+ } )
329
+ }
330
+ }
331
+
332
+ impl ToJson for CodeModel {
333
+ fn to_json ( & self ) -> Json {
334
+ match * self {
335
+ CodeModel :: Tiny => "tiny" ,
336
+ CodeModel :: Small => "small" ,
337
+ CodeModel :: Kernel => "kernel" ,
338
+ CodeModel :: Medium => "medium" ,
339
+ CodeModel :: Large => "large" ,
340
+ }
341
+ . to_json ( )
342
+ }
343
+ }
344
+
308
345
#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
309
346
pub enum TlsModel {
310
347
GeneralDynamic ,
@@ -699,7 +736,8 @@ pub struct TargetOptions {
699
736
/// -relocation-model=$relocation_model`. Defaults to `Pic`.
700
737
pub relocation_model : RelocModel ,
701
738
/// Code model to use. Corresponds to `llc -code-model=$code_model`.
702
- pub code_model : Option < String > ,
739
+ /// Defaults to `None` which means "inherited from the base LLVM target".
740
+ pub code_model : Option < CodeModel > ,
703
741
/// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec"
704
742
/// and "local-exec". This is similar to the -ftls-model option in GCC/Clang.
705
743
pub tls_model : TlsModel ,
@@ -1114,6 +1152,18 @@ impl Target {
1114
1152
Some ( Ok ( ( ) ) )
1115
1153
} ) ) . unwrap_or( Ok ( ( ) ) )
1116
1154
} ) ;
1155
+ ( $key_name: ident, CodeModel ) => ( {
1156
+ let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1157
+ obj. find( & name[ ..] ) . and_then( |o| o. as_string( ) . and_then( |s| {
1158
+ match s. parse:: <CodeModel >( ) {
1159
+ Ok ( code_model) => base. options. $key_name = Some ( code_model) ,
1160
+ _ => return Some ( Err ( format!( "'{}' is not a valid code model. \
1161
+ Run `rustc --print code-models` to \
1162
+ see the list of supported values.", s) ) ) ,
1163
+ }
1164
+ Some ( Ok ( ( ) ) )
1165
+ } ) ) . unwrap_or( Ok ( ( ) ) )
1166
+ } ) ;
1117
1167
( $key_name: ident, TlsModel ) => ( {
1118
1168
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
1119
1169
obj. find( & name[ ..] ) . and_then( |o| o. as_string( ) . and_then( |s| {
@@ -1266,7 +1316,7 @@ impl Target {
1266
1316
key ! ( only_cdylib, bool ) ;
1267
1317
key ! ( executables, bool ) ;
1268
1318
key ! ( relocation_model, RelocModel ) ?;
1269
- key ! ( code_model, optional ) ;
1319
+ key ! ( code_model, CodeModel ) ? ;
1270
1320
key ! ( tls_model, TlsModel ) ?;
1271
1321
key ! ( disable_redzone, bool ) ;
1272
1322
key ! ( eliminate_frame_pointer, bool ) ;
0 commit comments