From 654ef3f15b569d4e65d8b6b365f4cc82cc2b0eaf Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sat, 6 Feb 2021 23:58:02 -0500 Subject: [PATCH] [tools] Add tools/run.py to compile and immediately run scripts --- tools/format_trace.py | 3 +++ tools/run.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/trace.py | 15 +++++++++++---- 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 tools/run.py diff --git a/tools/format_trace.py b/tools/format_trace.py index a9732d2..16421e8 100644 --- a/tools/format_trace.py +++ b/tools/format_trace.py @@ -33,6 +33,9 @@ def handle_trace(lines, syms={}, only_debug=False): return x for line in lines: + if not line.strip(): + print("Blank line") + continue kind, *args = line.split() if kind == "MAKE": objs[args[0]] = syms.get(args[1], f"fn@{args[1]}") diff --git a/tools/run.py b/tools/run.py new file mode 100755 index 0000000..16e1717 --- /dev/null +++ b/tools/run.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import argparse +import subprocess +import tempfile +from pathlib import Path + +import trace + + +root = Path(__file__).parent.parent +ivy = root / 'target' / 'release' / 'ivy' +library_path = root / 'rt' / 'target' / 'release' + + +def compile(source, output): + subprocess.run( + [ivy, source, '-o', output], + env={'LIBRARY_PATH': library_path}, + check=True, + ) + + +def run(script, only_debug=True): + with tempfile.TemporaryDirectory() as d: + binary = Path(d) / 'a.out' + compile(script, output=binary) + trace.trace(binary, only_debug) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('script') + parser.add_argument('-v', '--verbose', action='store_true') + args = parser.parse_args() + run(args.script, not args.verbose) + + +if __name__ == '__main__': + main() diff --git a/tools/trace.py b/tools/trace.py index 9e1987e..b9c03bc 100644 --- a/tools/trace.py +++ b/tools/trace.py @@ -15,7 +15,13 @@ def get_trace(command): return lines[3:-4] -if __name__ == '__main__': +def trace(command, only_debug): + syms = format_trace.get_syms(command) + lines = get_trace(command) + format_trace.handle_trace(lines, syms, only_debug) + + +def main(): parser = argparse.ArgumentParser( description="Run an Ivy executable and format its runtime trace.", ) @@ -31,7 +37,8 @@ if __name__ == '__main__': parser.print_help() sys.exit(0) args = parser.parse_args() + trace(args.command, args.only_debug) - syms = format_trace.get_syms(args.command) - lines = get_trace(args.command) - format_trace.handle_trace(lines, syms, args.only_debug) + +if __name__ == '__main__': + main() -- 2.47.0