| #!/usr/bin/env python3 |
| """ |
| Generate tests for softrvv |
| TODO(henryherman) Look into combining the different template workflows |
| """ |
| import os |
| import logging |
| import argparse |
| from collections import namedtuple |
| from pathlib import Path |
| |
| from mako.lookup import TemplateLookup |
| import mako.exceptions |
| |
| parser = argparse.ArgumentParser( |
| description='Generate tests for vector instructions.') |
| |
| parser.add_argument('--template-path', dest='template_path', |
| help='path to templates', required=True) |
| parser.add_argument('--template', dest='template_name', |
| help='template name', required=True) |
| parser.add_argument('-v', '--verbose', help='increase output verbosity', |
| action='store_true') |
| parser.add_argument('--out-path', dest='out_path', |
| help='Path to output files', default='.') |
| parser.add_argument('--op', dest='op', |
| help='op instruction', default='') |
| |
| args = parser.parse_args() |
| |
| if args.verbose: |
| logging.basicConfig(level=logging.DEBUG) |
| |
| def main(): |
| """ Main routine for generating softrvv tests from templates.""" |
| mylookup = TemplateLookup(directories=[args.template_path, "."]) |
| try: |
| template = mylookup.get_template(args.template_name) |
| except mako.exceptions.TopLevelLookupException: |
| parser.error("Template does not exist %s" % args.template_name) |
| logging.debug("Template %s found", args.template_name) |
| Path(args.out_path).mkdir(parents=True, exist_ok=True) |
| outfile_name = args.template_name.replace(".tpl", "") |
| full_outfile_path = os.path.join(args.out_path, outfile_name) |
| logging.debug("Generating file %s", full_outfile_path) |
| with open(full_outfile_path, "w+") as outfile: |
| outfile.write(template.render(op=args.op)) |
| |
| if __name__ == "__main__": |
| main() |
| |
| |