Skip to content

Commit

Permalink
Fix kclvm cli args parse for -Y (#140)
Browse files Browse the repository at this point in the history
* fix(src/main.rs): fix kclvm_cli for parse arg `-Y`
fix kclvm_cli clap_app args parse of "-Y" in main.rs.
  • Loading branch information
He1pa authored Aug 10, 2022
1 parent 2ca76d5 commit b4bca7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
3 changes: 3 additions & 0 deletions kclvm/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ impl From<SettingsFile> for ExecProgramArgs {
let mut args = Self::default();
if let Some(cli_configs) = settings.kcl_cli_configs {
args.k_filename_list = cli_configs.files.unwrap_or_default();
if args.k_filename_list.is_empty() {
args.k_filename_list = cli_configs.file.unwrap_or_default();
}
args.strict_range_check = cli_configs.strict_range_check.unwrap_or_default();
args.disable_none = cli_configs.disable_none.unwrap_or_default();
args.verbose = cli_configs.verbose.unwrap_or_default() as i32;
Expand Down
12 changes: 9 additions & 3 deletions kclvm/sema/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ fn test_resolve_program_cycle_reference_fail() {

#[test]
fn test_record_used_module() {
let mut program = load_program(&["./src/resolver/test_data/record_used_module.k"], None).unwrap();
let mut program =
load_program(&["./src/resolver/test_data/record_used_module.k"], None).unwrap();
let scope = resolve_program(&mut program);
let main_scope = scope.scope_map.get(kclvm::MAIN_PKG_PATH).unwrap().borrow_mut().clone();
let main_scope = scope
.scope_map
.get(kclvm::MAIN_PKG_PATH)
.unwrap()
.borrow_mut()
.clone();
for (_, obj) in main_scope.elems {
let obj = obj.borrow_mut().clone();
if obj.kind == ScopeObjectKind::Module {
Expand All @@ -114,7 +120,7 @@ fn test_record_used_module() {
} else {
assert_eq!(obj.used, true);
}
}
}
}
}

Expand Down
39 changes: 25 additions & 14 deletions kclvm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
(@subcommand run =>
(@arg INPUT: ... "Sets the input file to use")
(@arg OUTPUT: -o --output +takes_value "Sets the LLVM IR/BC output file path")
(@arg SETTING: ... -Y --setting "Sets the input file to use")
(@arg SETTING: ... -Y --setting +takes_value "Sets the input file to use")
(@arg EMIT_TYPE: --emit +takes_value "Sets the emit type, expect (ast)")
(@arg BC_PATH: --bc +takes_value "Sets the linked LLVM bitcode file path")
(@arg verbose: -v --verbose "Print test information verbosely")
Expand All @@ -26,19 +26,30 @@ fn main() {
)
.get_matches();
if let Some(matches) = matches.subcommand_matches("run") {
if let Some(files) = matches.values_of("INPUT") {
let files: Vec<&str> = files.into_iter().collect::<Vec<&str>>();
// Config settings build
let settings = build_settings(&matches);
// Convert settings into execute arguments.
let args: ExecProgramArgs = settings.into();
// Parse AST program.
let program = load_program(&files, Some(args.get_load_program_options())).unwrap();
// Resolve AST program, generate libs, link libs and execute.
// TODO: The argument "plugin_agent" need to be read from python3.
execute(program, 0, &ExecProgramArgs::default()).unwrap();
} else {
println!("{}", matches.usage());
match (matches.values_of("INPUT"), matches.values_of("SETTING")) {
(None, None) => {
println!("{}", matches.usage());
}
(_, _) => {
let mut files: Vec<&str> = match matches.values_of("INPUT") {
Some(files) => files.into_iter().collect::<Vec<&str>>(),
None => vec![],
};
// Config settings build
let settings = build_settings(&matches);
// Convert settings into execute arguments.
let args: ExecProgramArgs = settings.into();
files = if !files.is_empty() {
files
} else {
args.get_files()
};
// Parse AST program.
let program = load_program(&files, Some(args.get_load_program_options())).unwrap();
// Resolve AST program, generate libs, link libs and execute.
// TODO: The argument "plugin_agent" need to be read from python3.
execute(program, 0, &ExecProgramArgs::default()).unwrap();
}
}
} else {
println!("{}", matches.usage());
Expand Down

0 comments on commit b4bca7b

Please sign in to comment.