blob: 55f470ef98f069ea0e591f651cf280c0330e53b2 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2023 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
#
# http://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.
"""
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()