Skip to content

Commit 1ee0aa9

Browse files
committed
Move BackendConfig to config.rs
1 parent 3d7d08f commit 1ee0aa9

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed

src/config.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::str::FromStr;
2+
3+
#[derive(Copy, Clone, Debug)]
4+
pub enum CodegenMode {
5+
Aot,
6+
Jit,
7+
JitLazy,
8+
}
9+
10+
impl Default for CodegenMode {
11+
fn default() -> Self {
12+
CodegenMode::Aot
13+
}
14+
}
15+
16+
impl FromStr for CodegenMode {
17+
type Err = String;
18+
19+
fn from_str(s: &str) -> Result<Self, Self::Err> {
20+
match s {
21+
"aot" => Ok(CodegenMode::Aot),
22+
"jit" => Ok(CodegenMode::Jit),
23+
"jit-lazy" => Ok(CodegenMode::JitLazy),
24+
_ => Err(format!("Unknown codegen mode `{}`", s)),
25+
}
26+
}
27+
}
28+
29+
#[derive(Copy, Clone, Debug, Default)]
30+
pub struct BackendConfig {
31+
pub codegen_mode: CodegenMode,
32+
}
33+
34+
impl BackendConfig {
35+
pub fn from_opts(opts: &[String]) -> Result<Self, String> {
36+
let mut config = BackendConfig::default();
37+
for opt in opts {
38+
if let Some((name, value)) = opt.split_once('=') {
39+
match name {
40+
"mode" => config.codegen_mode = value.parse()?,
41+
_ => return Err(format!("Unknown option `{}`", name)),
42+
}
43+
} else {
44+
return Err(format!("Invalid option `{}`", opt));
45+
}
46+
}
47+
Ok(config)
48+
}
49+
}

src/lib.rs

+2-48
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ extern crate rustc_target;
2323
extern crate rustc_driver;
2424

2525
use std::any::Any;
26-
use std::str::FromStr;
2726

2827
use rustc_codegen_ssa::traits::CodegenBackend;
2928
use rustc_codegen_ssa::CodegenResults;
@@ -36,6 +35,7 @@ use rustc_session::Session;
3635

3736
use cranelift_codegen::settings::{self, Configurable};
3837

38+
pub use crate::config::*;
3939
use crate::constant::ConstantCx;
4040
use crate::prelude::*;
4141

@@ -49,6 +49,7 @@ mod cast;
4949
mod codegen_i128;
5050
mod common;
5151
mod compiler_builtins;
52+
mod config;
5253
mod constant;
5354
mod debuginfo;
5455
mod discriminant;
@@ -161,53 +162,6 @@ impl<'m, 'tcx> CodegenCx<'m, 'tcx> {
161162
}
162163
}
163164

164-
#[derive(Copy, Clone, Debug)]
165-
pub enum CodegenMode {
166-
Aot,
167-
Jit,
168-
JitLazy,
169-
}
170-
171-
impl Default for CodegenMode {
172-
fn default() -> Self {
173-
CodegenMode::Aot
174-
}
175-
}
176-
177-
impl FromStr for CodegenMode {
178-
type Err = String;
179-
180-
fn from_str(s: &str) -> Result<Self, Self::Err> {
181-
match s {
182-
"aot" => Ok(CodegenMode::Aot),
183-
"jit" => Ok(CodegenMode::Jit),
184-
"jit-lazy" => Ok(CodegenMode::JitLazy),
185-
_ => Err(format!("Unknown codegen mode `{}`", s)),
186-
}
187-
}
188-
}
189-
190-
#[derive(Copy, Clone, Debug, Default)]
191-
pub struct BackendConfig {
192-
pub codegen_mode: CodegenMode,
193-
}
194-
195-
impl BackendConfig {
196-
fn from_opts(opts: &[String]) -> Result<Self, String> {
197-
let mut config = BackendConfig::default();
198-
for opt in opts {
199-
if let Some((name, value)) = opt.split_once('=') {
200-
match name {
201-
"mode" => config.codegen_mode = value.parse()?,
202-
_ => return Err(format!("Unknown option `{}`", name)),
203-
}
204-
} else {
205-
return Err(format!("Invalid option `{}`", opt));
206-
}
207-
}
208-
Ok(config)
209-
}
210-
}
211165

212166
pub struct CraneliftCodegenBackend {
213167
pub config: Option<BackendConfig>,

0 commit comments

Comments
 (0)