1- use std:: str:: FromStr ;
2-
31/// The mode to use for compilation.
42#[ derive( Copy , Clone , Debug ) ]
53pub enum CodegenMode {
@@ -11,19 +9,6 @@ pub enum CodegenMode {
119 JitLazy ,
1210}
1311
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-
2712/// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars.
2813#[ derive( Clone , Debug ) ]
2914pub struct BackendConfig {
@@ -38,27 +23,20 @@ pub struct BackendConfig {
3823 pub jit_args : Vec < String > ,
3924}
4025
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 {
4430 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) ;
5236 }
5337 } ,
54- }
55- }
56- }
38+ } ;
5739
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 ( ) ;
6240 for opt in opts {
6341 if opt. starts_with ( "-import-instr-limit" ) {
6442 // Silently ignore -import-instr-limit. It is set by rust's build system even when
@@ -67,7 +45,14 @@ impl BackendConfig {
6745 }
6846 if let Some ( ( name, value) ) = opt. split_once ( '=' ) {
6947 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+ }
7156 _ => return Err ( format ! ( "Unknown option `{}`" , name) ) ,
7257 }
7358 } else {
0 commit comments