Created
March 28, 2024 19:42
-
-
Save EricRahm/23249e5e503edd54172966b9ca864935 to your computer and use it in GitHub Desktop.
Script to invoke embossc front-end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Copyright 2024 Google LLC | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# https://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
"""Wrapper used to run the compiler front-end for profiling""" | |
import argparse | |
import os | |
import sys | |
import compiler.front_end.emboss_front_end | |
import compiler.back_end.cpp.emboss_codegen_cpp | |
def _parse_args(argv): | |
parser = argparse.ArgumentParser(description="Emboss compiler") | |
parser.add_argument("--import-dir", "-I", | |
dest="import_dirs", | |
action="append", | |
default=["."], | |
help="A directory to use when searching for imported " | |
"embs. If no import-dirs are specified, the " | |
"current directory will be used.") | |
parser.add_argument("--output-path", | |
nargs=1, | |
default=".", | |
help="Prefix to use for the generated output file.") | |
parser.add_argument("input_file", | |
type=str, | |
nargs=1, | |
help=".emb file to compile.") | |
return parser.parse_args(argv[1:]) | |
def main(argv): | |
flags = _parse_args(argv) | |
base_path = os.path.dirname(__file__) or "." | |
sys.path.append(base_path) | |
sys.path.append(os.path.join(base_path, "compiler", "util")) | |
ir_file = os.path.join(flags.output_path[0], flags.input_file[0]) + ".ir" | |
os.makedirs(os.path.dirname(ir_file), exist_ok=True) | |
front_end_args = [ | |
os.path.join(base_path, "compiler", "front_end", "emboss_front_end.py"), | |
"--output-file", ir_file | |
] | |
for import_dir in flags.import_dirs: | |
front_end_args.extend(["--import-dir", import_dir]) | |
front_end_args.append(flags.input_file[0]) | |
return compiler.front_end.emboss_front_end.main( | |
compiler.front_end.emboss_front_end._parse_command_line(front_end_args)) | |
if __name__ == "__main__": | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment