aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-10-25 00:33:15 -0600
committerMelody Horn <melody@boringcactus.com>2020-10-25 00:33:15 -0600
commit2a9b959245829efff2f0a2df1bd72180e75fc48a (patch)
treec2f81ea0398693c6685dfd7bbe4d44a7cc44d7a7
parenta013d906a550d835dc1e9287dc0af68057b667f4 (diff)
downloadreference-compiler-2a9b959245829efff2f0a2df1bd72180e75fc48a.tar.gz
reference-compiler-2a9b959245829efff2f0a2df1bd72180e75fc48a.zip
add crowbarc-reference script
-rw-r--r--crowbar_reference_compiler/__init__.py26
-rw-r--r--pyproject.toml3
2 files changed, 29 insertions, 0 deletions
diff --git a/crowbar_reference_compiler/__init__.py b/crowbar_reference_compiler/__init__.py
index 02fcfc1..92b9497 100644
--- a/crowbar_reference_compiler/__init__.py
+++ b/crowbar_reference_compiler/__init__.py
@@ -1,3 +1,29 @@
from .parser import parse_header, parse_implementation
from .scanner import scan
from .ssagen import compile_to_ssa
+
+
+def main():
+ import argparse
+
+ args = argparse.ArgumentParser(description='The reference compiler for the Crowbar programming language')
+ args.add_argument('-V', '--version', action='version', version='%(prog)s 0.0.2')
+ args.add_argument('-g', '--include-debug-info', action='store_true')
+ args.add_argument('-S', '--stop-at-assembly', action='store_true')
+ args.add_argument('-o', '--out', help='output file')
+ args.add_argument('input', help='input file')
+
+ args = args.parse_args()
+ if args.out is None:
+ args.out = args.input.replace('.cro', '.ssa')
+ with open(args.input, 'r', encoding='utf-8') as input_file:
+ input_code = input_file.read()
+ tokens = scan(input_code)
+ parse_tree = parse_implementation(tokens)
+ ssa = compile_to_ssa(parse_tree)
+ with open(args.out, 'w', encoding='utf-8') as output_file:
+ output_file.write(ssa)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/pyproject.toml b/pyproject.toml
index 15653f4..d1863aa 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,6 +13,9 @@ classifiers = [
"Topic :: Software Development :: Compilers",
]
+[tool.poetry.scripts]
+crowbarc-reference = "crowbar_reference_compiler:main"
+
[tool.poetry.dependencies]
python = "^3.7"
parsimonious = "^0.8.1"