|
11 | 11 |
|
12 | 12 | import argparse
|
13 | 13 | import os # Used to advertise this file's name ("autogenerated_note").
|
| 14 | +import sys |
| 15 | +import importlib.util |
14 | 16 |
|
15 | 17 | from UpdateTestChecks import common
|
16 | 18 |
|
|
20 | 22 | "llc",
|
21 | 23 | ]
|
22 | 24 |
|
| 25 | +# Helper that imports module from `module_path` and returns it. |
| 26 | +def import_module(module_path): |
| 27 | + if not os.path.exists(module_path): |
| 28 | + common.error("Path does not exist", module_path) |
| 29 | + sys.exit(1) |
| 30 | + module_name_with_ext = os.path.basename(module_path) |
| 31 | + module_name = os.path.splitext(module_name_with_ext)[0] |
| 32 | + spec = importlib.util.spec_from_file_location(module_name, module_path) |
| 33 | + module = importlib.util.module_from_spec(spec) |
| 34 | + sys.modules[module_name] = module |
| 35 | + spec.loader.exec_module(module) |
| 36 | + return module |
23 | 37 |
|
24 | 38 | def main():
|
25 | 39 | parser = argparse.ArgumentParser(description=__doc__)
|
@@ -67,6 +81,12 @@ def main():
|
67 | 81 | help="Set a default -march for when neither triple nor arch are found in a RUN line",
|
68 | 82 | )
|
69 | 83 | parser.add_argument("tests", nargs="+")
|
| 84 | + parser.add_argument( |
| 85 | + "--downstream-target-handler-path", |
| 86 | + default=None, |
| 87 | + dest="downstream_target_handler_path", |
| 88 | + help="The path of a python module that implements the scrubber and the regex generator and adds it to the targets handlers map for a downstream target", |
| 89 | + ) |
70 | 90 | initial_args = common.parse_commandline_args(parser)
|
71 | 91 |
|
72 | 92 | script_name = os.path.basename(__file__)
|
@@ -107,10 +127,15 @@ def main():
|
107 | 127 | march_in_cmd = m.groups()[0]
|
108 | 128 |
|
109 | 129 | m = common.DEBUG_ONLY_ARG_RE.search(llc_cmd)
|
110 |
| - if m and m.groups()[0] == "isel": |
111 |
| - from UpdateTestChecks import isel as output_type |
| 130 | + if initial_args.downstream_target_handler_path: |
| 131 | + common.warn("Downstream handlers provided by '%s'" |
| 132 | + % initial_args.downstream_target_handler_path) |
| 133 | + output_type = import_module(initial_args.downstream_target_handler_path) |
112 | 134 | else:
|
113 |
| - from UpdateTestChecks import asm as output_type |
| 135 | + if m and m.groups()[0] == "isel": |
| 136 | + from UpdateTestChecks import isel as output_type |
| 137 | + else: |
| 138 | + from UpdateTestChecks import asm as output_type |
114 | 139 |
|
115 | 140 | common.verify_filecheck_prefixes(filecheck_cmd)
|
116 | 141 |
|
|
0 commit comments