diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-04-11 11:11:39 +0100 |
---|---|---|
committer | Rupert Swarbrick <rswarbrick@lowrisc.org> | 2022-04-12 11:10:17 +0100 |
commit | 0d90f75dc4b5e28b2e3b3f35debaae1169c69d98 (patch) | |
tree | 5d42f6ff622688acfa3ae72486fbcd7c84cbf701 /spike_main | |
parent | 970466e6ebcf4957f131fde8b62ca10fb70b2bd6 (diff) | |
download | riscv-isa-sim-0d90f75dc4b5e28b2e3b3f35debaae1169c69d98.zip riscv-isa-sim-0d90f75dc4b5e28b2e3b3f35debaae1169c69d98.tar.gz riscv-isa-sim-0d90f75dc4b5e28b2e3b3f35debaae1169c69d98.tar.bz2 |
Slightly refactor --hartids parsing in spike.cc
We now parse to a std::vector<int> and then set the "hartids" variable
to the result.
There is a slight functional change here, in that if you pass
"--hartids 1,2,3 --hartids 4,5", you'll now get 2 cores with ids of
4,5 rather than 5 cores with ids of 1,2,3,4,5. This is what most tools
do with repeated command line arguments and I suspect the old
behaviour was actually by accident!
Diffstat (limited to 'spike_main')
-rw-r--r-- | spike_main/spike.cc | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 7791fbf..25d7c69 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -220,6 +220,21 @@ static unsigned long atoul_nonzero_safe(const char* s) return res; } +static std::vector<int> parse_hartids(const char *s) +{ + std::string const str(s); + std::stringstream stream(str); + std::vector<int> hartids; + + int n; + while (stream >> n) { + hartids.push_back(n); + if (stream.peek() == ',') stream.ignore(); + } + + return hartids; +} + int main(int argc, char** argv) { bool debug = false; @@ -265,18 +280,6 @@ int main(int argc, char** argv) /*default_priv=*/DEFAULT_PRIV, /*default_mem_layout=*/parse_mem_layout("2048")); - auto const hartids_parser = [&](const char *s) { - std::string const str(s); - std::stringstream stream(str); - - int n; - while (stream >> n) - { - hartids.push_back(n); - if (stream.peek() == ',') stream.ignore(); - } - }; - auto const device_parser = [&plugin_devices](const char *s) { const std::string str(s); std::istringstream stream(str); @@ -335,7 +338,7 @@ int main(int argc, char** argv) parser.option('H', 0, 0, [&](const char* s){halted = true;}); parser.option(0, "rbb-port", 1, [&](const char* s){use_rbb = true; rbb_port = atoul_safe(s);}); parser.option(0, "pc", 1, [&](const char* s){cfg.start_pc = strtoull(s, 0, 0);}); - parser.option(0, "hartids", 1, hartids_parser); + parser.option(0, "hartids", 1, [&](const char* s){hartids = parse_hartids(s);}); parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));}); parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));}); parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));}); |