diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2025-11-19 05:18:07 +0100 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2025-11-19 16:40:08 +0100 |
| commit | d2fb55d117f639246548d19c48ff7e9eabc15a8d (patch) | |
| tree | 57ef218a6de727c6b1ab597134b1a3f81bd810b9 | |
| parent | 0075d1b10c475d303a314a3425ee472252855f32 (diff) | |
| -rwxr-xr-x | salis.py | 57 |
1 files changed, 33 insertions, 24 deletions
@@ -12,7 +12,7 @@ import shutil import subprocess import sys -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, RawTextHelpFormatter +from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError, RawTextHelpFormatter from jinja2 import Environment, FileSystemLoader, StrictUndefined from tempfile import TemporaryDirectory @@ -40,38 +40,46 @@ new = parsers.add_parser("new", formatter_class=fclass, help="create new simul archs = os.listdir("./arch") uis = os.listdir("./ui") -intt = lambda i: int(i, 0) +def ipos(i): + ival = int(i, 0) + if ival < 0: raise ArgumentTypeError("value must be positive integer") + return ival -option_keys = ["short", "long", "metavar", "description", "default", "type", "parsers"] +def inat(i): + ival = int(i, 0) + if ival < 1: raise ArgumentTypeError("value must be greater than zero") + return ival + +option_keys = ["short", "long", "metavar", "description", "default", "required", "type", "parsers"] # fmt: off option_conf = [ ["A", "anc", "ANC", "ancestor file name without extension, to be compiled on " - "all cores (ANC points to 'ancs/<ARCH>/<ANC>.asm')", None, str, [bench, new]], - ["a", "arch", archs, "VM architecture", "dummy", str, [bench, new]], - ["b", "steps", "N", "number of steps to run in benchmark", 0x1000000, intt, [bench]], - ["C", "clones", "N", "number of ancestor clones on each core", 1, intt, [bench, new]], - ["c", "cores", "N", "number of simulator cores", 2, intt, [bench, new]], + "all cores (ANC points to 'ancs/<ARCH>/<ANC>.asm')", None, True, str, [bench, new]], + ["a", "arch", archs, "VM architecture", "dummy", False, str, [bench, new]], + ["b", "steps", "N", "number of steps to run in benchmark", 0x1000000, False, ipos, [bench]], + ["C", "clones", "N", "number of ancestor clones on each core", 1, False, inat, [bench, new]], + ["c", "cores", "N", "number of simulator cores", 2, False, inat, [bench, new]], ["d", "data-push-pow", "POW", "data aggregation interval exponent (interval == 2^POW >= " "thread sync interval); a value of 0 disables data " - "aggregation (requires 'sqlite')", 28, intt, [new]], - ["f", "force", None, "overwrite existing simulation of given name", False, bool, [new]], - ["F", "muta-flip", None, "cosmic rays flip bits instead of randomizing whole bytes", False, bool, [bench, new]], - ["M", "muta-pow", "POW", "mutator range exponent (range == 2^POW)", 32, intt, [bench, new]], - ["m", "mvec-pow", "POW", "memory vector size exponent (size == 2^POW)", 20, intt, [bench, new]], - ["n", "name", "NAME", "name of new or loaded simulation", "def.sim", str, [load, new]], - ["o", "optimized", None, "builds salis binary with optimizations", False, bool, [bench, load, new]], + "aggregation (requires 'sqlite')", 28, False, ipos, [new]], + ["f", "force", None, "overwrite existing simulation of given name", False, False, bool, [new]], + ["F", "muta-flip", None, "cosmic rays flip bits instead of randomizing whole bytes", False, False, bool, [bench, new]], + ["M", "muta-pow", "POW", "mutator range exponent (range == 2^POW)", 32, False, ipos, [bench, new]], + ["m", "mvec-pow", "POW", "memory vector size exponent (size == 2^POW)", 20, False, ipos, [bench, new]], + ["n", "name", "NAME", "name of new or loaded simulation", "def.sim", False, str, [load, new]], + ["o", "optimized", None, "builds salis binary with optimizations", False, False, bool, [bench, load, new]], ["p", "pre-cmd", "CMD", "shell command to wrap call to executable (e.g. gdb, " - "valgrind, etc.)", None, str, [bench, load, new]], - ["s", "seed", "SEED", "seed value for new simulation", 0, intt, [bench, new]], - ["S", "print-source", None, "print generated C source to stdout and exit", False, bool, [bench, load, new]], - ["T", "delete-temp-dir", None, "delete temporary directory on exit", True, bool, [bench, load, new]], + "valgrind, etc.)", None, False, str, [bench, load, new]], + ["s", "seed", "SEED", "seed value for new simulation", 0, False, ipos, [bench, new]], + ["S", "print-source", None, "print generated C source to stdout and exit", False, False, bool, [bench, load, new]], + ["T", "delete-temp-dir", None, "delete temporary directory on exit", True, False, bool, [bench, load, new]], ["t", "thread-gap", "N", "memory gap between cores in bytes (may help reduce cache " - "misses?)", 0x100, intt, [bench, load, new]], - ["u", "ui", uis, "user interface", "curses", str, [load, new]], - ["x", "compress", None, "compress save files (requires 'zlib')", True, bool, [new]], - ["y", "sync-pow", "POW", "core sync interval exponent (interval == 2^POW)", 20, intt, [bench, new]], - ["z", "auto-save-pow", "POW", "auto-save interval exponent (interval == 2^POW)", 36, intt, [new]], + "misses?)", 0x100, False, inat, [bench, load, new]], + ["u", "ui", uis, "user interface", "curses", False, str, [load, new]], + ["x", "compress", None, "compress save files (requires 'zlib')", True, False, bool, [new]], + ["y", "sync-pow", "POW", "core sync interval exponent (interval == 2^POW)", 20, False, ipos, [bench, new]], + ["z", "auto-save-pow", "POW", "auto-save interval exponent (interval == 2^POW)", 36, False, ipos, [new]], ] # fmt: on @@ -92,6 +100,7 @@ for parser, option in parser_map: arg_kwargs[key] = val push_diff("help", "description") + push_same("required") # No metavar means this argument is a flag if option["metavar"] is None: |
