From 2cf22d756a2f9c733329357add3543dc88f50909 Mon Sep 17 00:00:00 2001 From: Fatih Balli Date: Wed, 18 Oct 2023 13:18:10 +0000 Subject: [PATCH] Add optional `--synthesis-template` arg to parse.py Even though existing `--synthesis-file` parameter allows one to bring a custom yosys script, this is not very flexible, because it needs the source files hardcoded into the script. This is because, this argument does not use the yosys patching function `create_yosys_script` in `parse.py`. The new optional `--synthesis-template` allows one to pass a *template* yosys script that is still patched by `parse.py` so that source files do not have to be hard coded into the script. This gives the caller a good flexibility of controlling the synthesis flow without having to deal with source files. Ideal use case would be to pass both `--source` and `--synthesis-template` together. --- parse.py | 10 +++++++++- readme.md | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parse.py b/parse.py index f03190d..0cf9f7f 100755 --- a/parse.py +++ b/parse.py @@ -42,6 +42,11 @@ def parse_arguments(): help="Name of the top module") # Optional arguments + # Allow the caller to bring their own synthesis template + parser.add_argument("-st", "--synthesis-template", dest="synthesis_template_path", + default=TEMPLATE_FILE_PATH, + type=helpers.ap_check_file_exists, + help="Path of the template yosys synthesis script") parser.add_argument("-l", "--label", dest="label_file_path", required=False, default=LABEL_FILE_PATH, type=helpers.ap_check_dir_exists, help="Path of output label file (default: %(default)s)") @@ -78,7 +83,7 @@ def parse_arguments(): def create_yosys_script(args): yosys_script = "" - with open(TEMPLATE_FILE_PATH) as template_file: + with open(args.synthesis_template_path) as template_file: yosys_script += template_file.read() assert("{READ_FILES}" in yosys_script) read_verilog_commands = "\n".join(["read_verilog %s;" % os.path.abspath(f) for f in args.verilog_file_paths]) + "\n" @@ -109,6 +114,9 @@ def yosys_synth(args): if args.synthesis_file_path: print("Using custom yosys synthesis script: %s" % args.synthesis_file_path) yosys_synth_file_path = args.synthesis_file_path + elif args.synthesis_template_path: + print("Using custom yosys template synthesis script: %s" % args.synthesis_template_path) + yosys_synth_file_path = SYNTH_FILE_PATH else: yosys_synth_file_path = SYNTH_FILE_PATH diff --git a/readme.md b/readme.md index 26a4614..464612f 100644 --- a/readme.md +++ b/readme.md @@ -77,6 +77,7 @@ python3 parse.py The arguments for the standard mode of operation are: * `--source`: file path(s) to the source file(s). `parse.py` will automatically generate a Yosys synthesis script. Then, the `--synthesis-file` option must not be used. * `--synthesis-file`: In case one does not want to use the auto-generated script, this option can be used to specify a custom Yosys synthesis script. Then, the `--source` option must not be used because the script already includes the paths of the sources. + * `--synthesis-template`: an optional template yosys synthesis script that is used for patching instead of default `template/yosys_synth_template.txt`. The `--source` option can be used with this argument. The difference between `--synthesis-file` and `--synthesis-template` is that the former is directly passed to yosys, while the latter is patched with the source files passed with `--source`. * `--top-module`: the name of the top module Optional arguments include: