aboutsummaryrefslogtreecommitdiff
path: root/salis.py
diff options
context:
space:
mode:
Diffstat (limited to 'salis.py')
-rwxr-xr-xsalis.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/salis.py b/salis.py
index a3281b5..76290ee 100755
--- a/salis.py
+++ b/salis.py
@@ -123,25 +123,21 @@ for parser, option in parser_map:
args = main_parser.parse_args()
-
-def log(msg, val=""):
- print(f"\033[1;34m{msg}\033[0m", val, flush=True)
-
+def info(msg, val=""):
+ print(f"\033[1;34mINFO:\033[0m {msg}", val)
def warn(msg, val=""):
- print(f"\033[1;31m{msg}\033[0m", val, flush=True)
-
+ print(f"\033[1;31mWARN:\033[0m {msg}", val)
def error(msg, val=""):
- warn(f"ERROR: {msg}", val)
+ print(f"\033[1;31mERROR:\033[0m {msg}", val)
sys.exit(1)
-
# ------------------------------------------------------------------------------
# Load configuration
# ------------------------------------------------------------------------------
-log(headline)
-log(f"Called '{script}' with the following options:")
+info(headline)
+info(f"Called '{script}' with the following options:")
for key, val in vars(args).items():
print(f"{key} = {repr(val)}")
@@ -155,7 +151,7 @@ if args.command in ["load"]:
if not os.path.isdir(sim_dir):
error("No simulation found named:", args.name)
- log(f"Sourcing configuration from '{sim_opts}':")
+ info(f"Sourcing configuration from '{sim_opts}':")
sys.path.append(sim_dir)
import opts as opts_module
@@ -178,10 +174,10 @@ if args.command in ["new"]:
if os.path.isdir(sim_dir):
error("Simulation directory found at:", sim_dir)
- log("Creating new simulation directory at:", sim_dir)
+ info("Creating new simulation directory at:", sim_dir)
os.mkdir(sim_dir)
- log("Creating configuration file at:", sim_opts)
+ info("Creating configuration file at:", sim_opts)
opts = (
option["long"].replace("-", "_")
@@ -197,13 +193,13 @@ if args.command in ["new"]:
# Load architecture and UI variables
# ------------------------------------------------------------------------------
arch_path = f"arch/{args.arch}"
-log("Loading architecture specific variables from:", f"{arch_path}/arch_vars.py")
+info("Loading architecture specific variables from:", f"{arch_path}/arch_vars.py")
sys.path.append(arch_path)
import arch_vars
if args.command in ["load", "new"]:
ui_path = f"ui/{args.ui}"
- log("Loading UI specific variables from:", f"{ui_path}/ui_vars.py")
+ info("Loading UI specific variables from:", f"{ui_path}/ui_vars.py")
sys.path.append(ui_path)
import ui_vars
@@ -215,6 +211,7 @@ ul_pow = lambda val: f"{hex(2 ** val)}ul"
includes = [
"assert.h",
+ "stdarg.h",
"stdbool.h",
"stddef.h",
"stdint.h",
@@ -249,13 +246,13 @@ if args.command in ["load", "new"]:
data_push_interval = ul_pow(args.data_push_pow)
data_push_busy_timeout = 600000
includes.append("sqlite3.h")
- log("Data will be aggregated at:", data_push_path)
+ info("Data will be aggregated at:", data_push_path)
else:
warn("Data aggregation disabled")
if args.compress:
includes.append("zlib.h")
- log("Save file compression enabled")
+ info("Save file compression enabled")
else:
warn("Save file compression disabled")
@@ -295,16 +292,16 @@ if args.command in ["bench", "new"] and args.anc is not None:
if not found:
error("Unrecognized instruction in ancestor file:", line)
- log(f"Compiled ancestor file '{anc_path}' into byte array:", anc_bytes)
+ info(f"Compiled ancestor file '{anc_path}' into byte array:", anc_bytes)
# ------------------------------------------------------------------------------
# Emit C source
# ------------------------------------------------------------------------------
tempdir = TemporaryDirectory(prefix="salis_", delete=args.delete_temp_dir)
-log("Created a temporary salis directory at:", tempdir.name)
+info("Created a temporary salis directory at:", tempdir.name)
salis_src = f"{tempdir.name}/salis.c"
-log("Emitting C source at:", salis_src)
+info("Emitting C source at:", salis_src)
jinja_env = Environment(
loader = FileSystemLoader("."),
@@ -316,7 +313,7 @@ jinja_env = Environment(
source_str = jinja_env.get_template("core.j2.c").render(**locals())
if args.print_source:
- log("Printing C source and exiting...")
+ info("Printing C source and exiting...")
print(source_str)
exit(0)
@@ -327,7 +324,7 @@ with open(salis_src, "w") as file:
# Build executable
# ------------------------------------------------------------------------------
salis_bin = f"{tempdir.name}/salis_bin"
-log("Building salis binary at:", salis_bin)
+info("Building salis binary at:", salis_bin)
build_cmd = ["gcc", salis_src, "-o", salis_bin, "-Wall", "-Wextra", "-Werror", "-Wno-overlength-strings", "-pedantic", "-std=c11"]
build_cmd.extend(["-O3", "-DNDEBUG"] if args.optimized else ["-ggdb"])
@@ -342,19 +339,19 @@ if args.command in ["load", "new"]:
# This allows managing large SQL strings more easily
build_cmd.extend(["-lsqlite3", "-D_GNU_SOURCE"] if args.data_push_pow != 0 else [])
-log("Using build command:", " ".join(build_cmd))
+info("Using build command:", " ".join(build_cmd))
subprocess.run(build_cmd, check=True)
# ------------------------------------------------------------------------------
# Run salis binary
# ------------------------------------------------------------------------------
-log("Running salis binary...")
+info("Running salis binary...")
run_cmd = [args.pre_cmd] if args.pre_cmd else []
run_cmd.append(salis_bin)
-log("Using run command:", " ".join(run_cmd))
-salis_sp = subprocess.Popen(run_cmd, stdout=sys.stdout)
+info("Using run command:", " ".join(run_cmd))
+salis_sp = subprocess.Popen(run_cmd, stdout=sys.stdout, stderr=sys.stderr)
# Ctrl-C terminates the simulator gracefully.
# When using signals (e.g. SIGTERM), they must be sent to the entire process group
@@ -364,3 +361,8 @@ try:
except KeyboardInterrupt:
salis_sp.terminate()
salis_sp.wait()
+
+code = salis_sp.returncode
+
+if code != 0:
+ error("Salis binary returned code:", code)