Skip to content

Commit dae731d

Browse files
committed
feat: enhance configuration management with AppConfig
1 parent e3ee58a commit dae731d

File tree

18 files changed

+635
-242
lines changed

18 files changed

+635
-242
lines changed

bebop/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
config
1+
m5out

bebop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sim = "0.13"
1212
serde = { version = "1.0", features = ["derive"] }
1313
serde_json = "1.0"
1414
toml = "0.8"
15+
config = "0.14"
1516
rustyline = "14.0"
1617
clap = { version = "4.5", features = ["derive"] }
1718
log = "0.4"

bebop/bin/bebop.rs

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use bebop::simulator::host::host::HostConfig;
2-
use bebop::simulator::sim::mode::{ArchType, HostType, SimConfig, StepMode};
1+
use bebop::simulator::config::config::load_and_merge_configs;
32
use bebop::simulator::utils::log::init_log;
43
use bebop::simulator::Simulator;
54
use clap::Parser;
5+
use std::path::PathBuf;
66

77
/// Bebop - A RISC-V NPU simulator
88
#[derive(Parser, Debug)]
@@ -22,58 +22,66 @@ struct Args {
2222
#[arg(long, value_name = "FILE")]
2323
trace_file: Option<String>,
2424

25-
/// Architecture type: buckyball or gemmini (default: buckyball)
26-
#[arg(short, long, value_name = "ARCH", default_value = "buckyball")]
27-
arch: String,
25+
/// Architecture type: buckyball or gemmini
26+
#[arg(short, long, value_name = "ARCH")]
27+
arch: Option<String>,
2828

29-
/// Host type: spike or gem5 (default: spike)
30-
#[arg(long, value_name = "HOST", default_value = "spike")]
31-
host: String,
29+
/// Host type: spike or gem5
30+
#[arg(long, value_name = "HOST")]
31+
host: Option<String>,
3232

33-
/// Host config file path (default: use default host.toml)
33+
/// Test binary path
3434
#[arg(long, value_name = "FILE")]
35-
host_config: Option<String>,
35+
test_binary: Option<String>,
36+
37+
/// Custom config file path (default: use default.toml)
38+
#[arg(long, value_name = "FILE")]
39+
config_file: Option<String>,
40+
41+
/// gem5 SE mode: binary path
42+
#[arg(long, value_name = "FILE")]
43+
se_binary: Option<String>,
44+
45+
/// gem5 FS mode: kernel path
46+
#[arg(long, value_name = "FILE")]
47+
fs_kernel: Option<String>,
48+
49+
/// gem5 FS mode: disk image path
50+
#[arg(long, value_name = "FILE")]
51+
fs_image: Option<String>,
52+
53+
/// gem5 mode: se or fs
54+
#[arg(long, value_name = "MODE")]
55+
gem5_mode: Option<String>,
3656
}
3757

3858
fn main() -> std::io::Result<()> {
3959
init_log();
4060

4161
let args = Args::parse();
4262

43-
let step_mode = if args.step {
44-
StepMode::Step
45-
} else {
46-
StepMode::Continuous
47-
};
48-
49-
let arch_type = match args.arch.to_lowercase().as_str() {
50-
"gemmini" => ArchType::Gemmini,
51-
"buckyball" => ArchType::Buckyball,
52-
_ => {
53-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, format!("Unknown architecture: {}", args.arch)));
54-
}
55-
};
56-
57-
let host_type = match args.host.to_lowercase().as_str() {
58-
"spike" => HostType::Spike,
59-
"gem5" => HostType::Gem5,
60-
_ => {
61-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, format!("Unknown host type: {}", args.host)));
62-
}
63-
};
64-
65-
let config = SimConfig {
66-
quiet: args.quiet,
67-
step_mode,
68-
trace_file: args.trace_file,
69-
arch_type,
70-
host_type,
71-
host_config: args.host_config,
72-
};
73-
74-
let host_config = HostConfig::from_sim_config(&config);
75-
76-
let mut simulator = Simulator::new(config, host_config)?;
63+
// 获取bebop文件夹路径(CARGO_MANIFEST_DIR)
64+
let bebop_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
65+
let bebop_root = bebop_root.join("..").to_path_buf();
66+
67+
// 加载并合并配置
68+
let app_config = load_and_merge_configs(
69+
args.config_file.as_deref(),
70+
&bebop_root,
71+
args.quiet,
72+
args.step,
73+
args.trace_file.as_deref(),
74+
args.arch.as_deref(),
75+
args.host.as_deref(),
76+
args.test_binary.as_deref(),
77+
args.se_binary.as_deref(),
78+
args.fs_kernel.as_deref(),
79+
args.fs_image.as_deref(),
80+
args.gem5_mode.as_deref(),
81+
)?;
82+
83+
// 从AppConfig直接创建Simulator
84+
let mut simulator = Simulator::from_app_config(&app_config)?;
7785

7886
simulator.run()
7987
}

0 commit comments

Comments
 (0)