aboutsummaryrefslogtreecommitdiff
path: root/salis
diff options
context:
space:
mode:
Diffstat (limited to 'salis')
-rwxr-xr-xsalis79
1 files changed, 46 insertions, 33 deletions
diff --git a/salis b/salis
index a493861..ad5aded 100755
--- a/salis
+++ b/salis
@@ -11,7 +11,7 @@
set -euo pipefail
headline="Salis: Simple A-Life Simulator."
-help_msg="show help and exit"
+help_msg="Shows help and exits"
usage() {
cat << EOF
@@ -22,9 +22,9 @@ Options:
-h, --help ${help_msg}
Commands:
- bench run benchmark test
- load load saved simulation
- new create a new simulation
+ bench Runs benchmark
+ load Loads saved simulation
+ new Creates a new simulation
Use '-h' to list arguments for each command.
Example: ${0} bench -h
@@ -35,7 +35,7 @@ case ${1:-} in
bench|load|new)
;;
-h|--help)
- usage | less -CQS~
+ usage
exit 0
;;
"")
@@ -60,38 +60,39 @@ arches=`falter arch`
uis=`falter ui`
anc_def_desc() {
- echo "default ancestor file name without extension, "
+ echo "Default ancestor file name without extension, "
echo "to be compiled on all cores "
echo "('ANC' points to file 'ancs/<ARCH>/<ANC>.asm')"
}
anc_spec_def() {
- echo "core specific ancestor file names separated by commas, "
- echo "using same convention as with default ancestor (<ANC0>,<ANC1>,...), "
- echo "when provided will override default ancestor on specified cores"
+ echo "Core specific ancestor file names separated by commas, "
+ echo "using same convention as with default ancestor (<ANC0>,<ANC1>,...). "
+ echo "When provided will override default ancestor on specified cores."
}
options=(
"A|anc-def|ANC|`anc_def_desc`|||bench:new"
"a|arch|ARCH|VM architecture|${arches}|dummy|bench:new"
- "b|steps|N|number of steps to run in benchmark||0x1000000|bench"
- "C|clones|N|number of ancestor clones on each core||1|bench:new"
- "c|cores|N|number of simulator cores||2|bench:new"
- "F|muta-flip||cosmic rays flip bits instead of randomizing whole bytes||false|bench:new"
- "f|force||overwrite existing simulation of given name||false|new"
- "H|half||compile ancestor at the middle of the memory buffer||false|bench:new"
+ "b|steps|N|Number of steps to run in benchmark||0x1000000|bench"
+ "C|clones|N|Number of ancestor clones on each core||1|bench:new"
+ "c|cores|N|Number of simulator cores||2|bench:new"
+ "F|muta-flip||Cosmic rays flip bits instead of randomizing whole bytes||false|bench:new"
+ "f|force||Overwrites existing simulation of given name||false|new"
+ "H|half||Compiles ancestor at the middle of the memory buffer||false|bench:new"
"h|help||${help_msg}|||bench:load:new"
- "M|muta-pow|POW|mutator range exponent (range == 2^POW)||32|bench:new"
- "m|mvec-pow|POW|memory vector size exponent (size == 2^POW)||20|bench:new"
- "n|name|NAME|name of new or loaded simulation||def.sim|load:new"
- "o|optimized||build Salis binary with optimizations||false|bench:load:new"
- "p|pre-cmd|CMD|shell command to wrap executable (e.g. gdb)|||bench:load:new"
+ "M|muta-pow|POW|Mutator range exponent (range == 2^POW)||32|bench:new"
+ "m|mvec-pow|POW|Memory vector size exponent (size == 2^POW)||20|bench:new"
+ "n|name|NAME|Name of new or loaded simulation||def.sim|load:new"
+ "o|optimized||Builds Salis binary with optimizations||false|bench:load:new"
+ "p|pre-cmd|CMD|Shell command to wrap executable (e.g. gdb, valgrind, etc.)|||bench:load:new"
"S|anc-spec|ANC0,ANC1,...|`anc_spec_def`|||bench:new"
- "s|seed|SEED|seed value for new simulation||0|bench:new"
- "t|thread-gap|N|memory gap between cores (in bytes)||0x100|bench:load:new"
- "u|ui|UI|user interface|${uis}|curses|load:new"
- "y|sync-pow|POW|core sync interval exponent (interval == 2^POW)||20|bench:new"
- "z|auto-save-pow|POW|auto save interval exponent (interval == 2^POW)||36|new"
+ "s|seed|SEED|Seed value for new simulation||0|bench:new"
+ "t|thread-gap|N|Memory gap between cores in bytes (could help reduce cache misses?)||0x100|bench:load:new"
+ "u|ui|UI|User interface|${uis}|curses|load:new"
+ "y|sync-pow|POW|Core sync interval exponent (interval == 2^POW)||20|bench:new"
+ "x|compress||Compress save files (requires 'zlib')||true|new"
+ "z|auto-save-pow|POW|Auto-save interval exponent (interval == 2^POW)||36|new"
)
field() {
@@ -111,7 +112,7 @@ fhelp() {
lopt=`field "${1}" 2`
meta=`field "${1}" 3`
- printf %-32s " -${sopt}, --${lopt}`[[ -n ${meta} ]] && echo " ${meta}"`"
+ printf "%s\r" " -${sopt}, --${lopt}`[[ -n ${meta} ]] && echo " ${meta}"`"
help=`field "${1}" 4`
choi=`field "${1}" 5`
@@ -119,7 +120,7 @@ fhelp() {
copt=`[[ -n ${choi} ]] && echo " (choices: ${choi/:/, })"`
dopt=`[[ -n ${defv} ]] && echo " (default: ${defv})"`
- echo ${help}${copt}${dopt}
+ echo -e "\t\t\t\t${help}${copt}${dopt}" | fmt -w120
}
fshort() {
@@ -168,7 +169,7 @@ fiter() {
usage() {
cat << EOF
${headline}
-Usage: ${0} ${cmd} `fiter flist`
+Usage: ${0} ${cmd} `fiter flist | fmt -t -w120`
Options:
`fiter fhelp`
@@ -196,7 +197,8 @@ parse_next() {
nopt=opt_${lopt//-/_}
if [[ -z ${meta} ]] ; then
- eval ${nopt}=true
+ defv=`field "${vopt}" 6`
+ eval ${nopt}=`[[ ${defv} == true ]] && echo false || echo true`
shift_next=1
else
eval ${nopt}=${2}
@@ -208,7 +210,7 @@ parse_next() {
while true ; do
case ${1} in
-h|--help)
- usage | less -CQS~
+ usage
exit 0
;;
--)
@@ -275,7 +277,7 @@ act_new=3
act_var="act_${cmd}"
-gcc_flags="-Wall -Wextra -Werror -std=c11 -pedantic"
+gcc_flags="-Wall -Wextra -Werror -std=gnu11 -pedantic"
fquote() {
echo "\\\"${1}\\\""
@@ -285,7 +287,7 @@ fpow() {
printf '%#xul' $((1 << ${1}))
}
-bcmd="gcc src/salis.c -o ${salis_exe} ${gcc_flags} -Isrc -lncursesw -pthread"
+bcmd="gcc src/salis.c -o ${salis_exe} ${gcc_flags} -Isrc -pthread"
bcmd="${bcmd} `[[ ${opt_optimized} == true ]] && echo "-O3 -DNDEBUG" || echo "-ggdb"`"
bcmd="${bcmd} -DACTION=${!act_var}"
bcmd="${bcmd} -DARCHITECTURE=`fquote ${opt_arch}`"
@@ -337,7 +339,18 @@ load|new)
bcmd="${bcmd} -DMUTA_FLIP_BIT=`[[ ${opt_muta_flip} == true ]] && echo 1 || echo 0`"
bcmd="${bcmd} -DSIM_NAME=`fquote ${opt_name}`"
bcmd="${bcmd} -DSIM_PATH=`fquote ${sim_path}`"
- bcmd="${bcmd} -DUI=`fquote ui/${opt_ui}.c`"
+
+ ui_file=ui/${opt_ui}.c
+ ui_flags=`sed -n -e 's/^.*GCC_EXTRA_FLAGS //p' src/${ui_file}`
+
+ shopt -s extglob
+ bcmd="${bcmd} -DUI=`fquote ${ui_file}` ${ui_flags}"
+ bcmd="${bcmd%%*( )}"
+ shopt -u extglob
+
+ if [[ ${opt_compress} == true ]] ; then
+ bcmd="${bcmd} -DCOMPRESS -lz"
+ fi
;;
esac