diff options
author | Robert Norton <rmn30@cam.ac.uk> | 2019-07-01 10:30:45 +0100 |
---|---|---|
committer | Robert Norton <rmn30@cam.ac.uk> | 2019-07-01 10:30:45 +0100 |
commit | efdbcdb53c9f11cf259443c5768fff168cfe50a0 (patch) | |
tree | 4e91d16ee662f906b761b0fd89aa4fa89d5dab66 /c_emulator/riscv_sim.c | |
parent | df76662199ccc9f5e2cafbf767ab1549a957036d (diff) | |
download | sail-riscv-efdbcdb53c9f11cf259443c5768fff168cfe50a0.zip sail-riscv-efdbcdb53c9f11cf259443c5768fff168cfe50a0.tar.gz sail-riscv-efdbcdb53c9f11cf259443c5768fff168cfe50a0.tar.bz2 |
Improve argument parsing of C emulator. Make trace / no-trace argument optional.
Diffstat (limited to 'c_emulator/riscv_sim.c')
-rw-r--r-- | c_emulator/riscv_sim.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 12c82ce..9934613 100644 --- a/c_emulator/riscv_sim.c +++ b/c_emulator/riscv_sim.c @@ -70,7 +70,12 @@ bool config_print_mem_access = true; bool config_print_platform = true; void set_config_print(char *var, bool val) { - if (strcmp("instr", optarg) == 0) { + if (optarg == NULL || strcmp("all", optarg) == 0) { + config_print_instr = val; + config_print_mem_access = val; + config_print_reg = val; + config_print_platform = val; + } else if (strcmp("instr", optarg) == 0) { config_print_instr = val; } else if (strcmp("reg", optarg) == 0) { config_print_reg = val; @@ -78,13 +83,8 @@ void set_config_print(char *var, bool val) { config_print_mem_access = val; } else if (strcmp("platform", optarg) == 0) { config_print_platform = val; - } else if (strcmp("all", optarg) == 0) { - config_print_instr = val; - config_print_mem_access = val; - config_print_reg = val; - config_print_platform = val; } else { - fprintf(stderr, "Unknown trace category: %s (should be instr|reg|mem|platform|all)\n", var); + fprintf(stderr, "Unknown trace category: '%s' (should be instr|reg|mem|platform|all)\n", var); exit(1); } } @@ -109,8 +109,8 @@ static struct option options[] = { {"rvfi-dii", required_argument, 0, 'r'}, #endif {"help", no_argument, 0, 'h'}, - {"trace", required_argument, 0, 'v'}, - {"no-trace", required_argument, 0, 'V'}, + {"trace", optional_argument, 0, 'v'}, + {"no-trace", optional_argument, 0, 'V'}, {0, 0, 0, 0} }; @@ -123,7 +123,7 @@ static void print_usage(const char *argv0, int ec) #endif struct option *opt = options; while (opt->name) { - fprintf(stdout, "\t -%c\t %s\n", (char)opt->val, opt->name); + fprintf(stdout, "\t -%c\t --%s\n", (char)opt->val, opt->name); opt++; } exit(ec); @@ -194,7 +194,7 @@ char *process_args(int argc, char **argv) int c, idx = 1; uint64_t ram_size = 0; while(true) { - c = getopt_long(argc, argv, "admCIispz:b:t:v:hr:T:V:v:", options, &idx); + c = getopt_long(argc, argv, "admCIispz:b:t:v:hr:T:V::v::", options, &idx); if (c == -1) break; switch (c) { case 'a': @@ -269,6 +269,9 @@ char *process_args(int argc, char **argv) case 'v': set_config_print(optarg, true); break; + case '?': + print_usage(argv[0], 1); + break; } } if (do_dump_dts) dump_dts(); |