1
- use std:: str:: FromStr ;
2
-
3
1
/// The mode to use for compilation.
4
2
#[ derive( Copy , Clone , Debug ) ]
5
3
pub enum CodegenMode {
@@ -11,19 +9,6 @@ pub enum CodegenMode {
11
9
JitLazy ,
12
10
}
13
11
14
- impl FromStr for CodegenMode {
15
- type Err = String ;
16
-
17
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
18
- match s {
19
- "aot" => Ok ( CodegenMode :: Aot ) ,
20
- "jit" => Ok ( CodegenMode :: Jit ) ,
21
- "jit-lazy" => Ok ( CodegenMode :: JitLazy ) ,
22
- _ => Err ( format ! ( "Unknown codegen mode `{}`" , s) ) ,
23
- }
24
- }
25
- }
26
-
27
12
/// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars.
28
13
#[ derive( Clone , Debug ) ]
29
14
pub struct BackendConfig {
@@ -38,27 +23,20 @@ pub struct BackendConfig {
38
23
pub jit_args : Vec < String > ,
39
24
}
40
25
41
- impl Default for BackendConfig {
42
- fn default ( ) -> Self {
43
- BackendConfig {
26
+ impl BackendConfig {
27
+ /// Parse the configuration passed in using `-Cllvm-args`.
28
+ pub fn from_opts ( opts : & [ String ] ) -> Result < Self , String > {
29
+ let mut config = BackendConfig {
44
30
codegen_mode : CodegenMode :: Aot ,
45
- jit_args : {
46
- match std:: env:: var ( "CG_CLIF_JIT_ARGS" ) {
47
- Ok ( args) => args. split ( ' ' ) . map ( |arg| arg. to_string ( ) ) . collect ( ) ,
48
- Err ( std:: env:: VarError :: NotPresent ) => vec ! [ ] ,
49
- Err ( std:: env:: VarError :: NotUnicode ( s) ) => {
50
- panic ! ( "CG_CLIF_JIT_ARGS not unicode: {:?}" , s) ;
51
- }
31
+ jit_args : match std:: env:: var ( "CG_CLIF_JIT_ARGS" ) {
32
+ Ok ( args) => args. split ( ' ' ) . map ( |arg| arg. to_string ( ) ) . collect ( ) ,
33
+ Err ( std:: env:: VarError :: NotPresent ) => vec ! [ ] ,
34
+ Err ( std:: env:: VarError :: NotUnicode ( s) ) => {
35
+ panic ! ( "CG_CLIF_JIT_ARGS not unicode: {:?}" , s) ;
52
36
}
53
37
} ,
54
- }
55
- }
56
- }
38
+ } ;
57
39
58
- impl BackendConfig {
59
- /// Parse the configuration passed in using `-Cllvm-args`.
60
- pub fn from_opts ( opts : & [ String ] ) -> Result < Self , String > {
61
- let mut config = BackendConfig :: default ( ) ;
62
40
for opt in opts {
63
41
if opt. starts_with ( "-import-instr-limit" ) {
64
42
// Silently ignore -import-instr-limit. It is set by rust's build system even when
@@ -67,7 +45,14 @@ impl BackendConfig {
67
45
}
68
46
if let Some ( ( name, value) ) = opt. split_once ( '=' ) {
69
47
match name {
70
- "mode" => config. codegen_mode = value. parse ( ) ?,
48
+ "mode" => {
49
+ config. codegen_mode = match value {
50
+ "aot" => CodegenMode :: Aot ,
51
+ "jit" => CodegenMode :: Jit ,
52
+ "jit-lazy" => CodegenMode :: JitLazy ,
53
+ _ => return Err ( format ! ( "Unknown codegen mode `{}`" , value) ) ,
54
+ } ;
55
+ }
71
56
_ => return Err ( format ! ( "Unknown option `{}`" , name) ) ,
72
57
}
73
58
} else {
0 commit comments