diff options
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | crowbar_reference_compiler/__init__.py | 12 |
2 files changed, 16 insertions, 4 deletions
@@ -7,7 +7,8 @@ requirements: usage (i probably will forget to update this so [check directly](https://git.sr.ht/~boringcactus/crowbar-reference-compiler/tree/main/crowbar_reference_compiler/__init__.py)): ``` usage: crowbarc-reference [-h] [-V] [-g] [--stop-at-parse-tree] - [--stop-at-qbe-ssa] [-S] [-o OUT] + [--stop-at-qbe-ssa] [-S] [-c] [-D DEFINE_CONSTANT] + [-I INCLUDE_DIR] [-o OUT] input The reference compiler for the Crowbar programming language @@ -22,5 +23,10 @@ optional arguments: --stop-at-parse-tree --stop-at-qbe-ssa -S, --stop-at-assembly + -c, --stop-at-object + -D DEFINE_CONSTANT, --define-constant DEFINE_CONSTANT + define a constant with some literal value + -I INCLUDE_DIR, --include-dir INCLUDE_DIR + folder to look for included headers within -o OUT, --out OUT output file ``` diff --git a/crowbar_reference_compiler/__init__.py b/crowbar_reference_compiler/__init__.py index d4e7430..c348104 100644 --- a/crowbar_reference_compiler/__init__.py +++ b/crowbar_reference_compiler/__init__.py @@ -14,6 +14,9 @@ def main(): args.add_argument('--stop-at-parse-tree', action='store_true') args.add_argument('--stop-at-qbe-ssa', action='store_true') args.add_argument('-S', '--stop-at-assembly', action='store_true') + args.add_argument('-c', '--stop-at-object', action='store_true') + args.add_argument('-D', '--define-constant', help='define a constant with some literal value') + args.add_argument('-I', '--include-dir', help='folder to look for included headers within') args.add_argument('-o', '--out', help='output file') args.add_argument('input', help='input file') @@ -38,20 +41,23 @@ def main(): # TODO bundle the qbe binary or something qbe_result = subprocess.run(['qbe', '-'], input=ssa, capture_output=True, text=True) if qbe_result.returncode != 0: - if args.out is None: - args.out = args.input.replace('.cro', '.s') print(qbe_result.stderr, file=sys.stderr) sys.exit(1) asm = qbe_result.stdout if args.stop_at_assembly: if args.out is None: - args.out = args.input.replace('.cro', '.o') + args.out = args.input.replace('.cro', '.s') with open(args.out, 'w', encoding='utf-8') as output_file: output_file.write(asm) return if args.out is None: args.out = args.input.replace('.cro', '.out') # TODO don't assume gcc is always the right thing + extra_gcc_flags = [] + if args.stop_at_object: + if args.out is None: + args.out = args.input.replace('.cro', '.o') + extra_gcc_flags.append('-c') gcc_result = subprocess.run(['gcc', '-x', 'assembler', '-o', args.out, '-'], input=asm, text=True) sys.exit(gcc_result.returncode) |