From 58098a7b1ffcf41da759f862deb753c82fe5b4b0 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Fri, 5 Aug 2022 15:40:12 -0700 Subject: Machine parsable specification This converts portions of the asciidoc specification into an xml document and schema. For the html and pdf outputs, the xml is converted to asciidoc files that are included into the existing specification. The xml allows future automated uses of the tosa specification while maintaining rough compatibility with the existing document. No significant functional changes are included in this change. Change-Id: I7f1f95c527638e270c157d58fcdec6a3510daea5 Signed-off-by: Eric Kunze --- tools/genspec.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tools/genspec.py (limited to 'tools/genspec.py') diff --git a/tools/genspec.py b/tools/genspec.py new file mode 100755 index 0000000..c871b75 --- /dev/null +++ b/tools/genspec.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +import os + +import tosa + + +class TOSASpecAsciidocGenerator: + def __init__(self, spec): + self.spec = spec + + def generate_operator(self, op, file): + file.write("\n*Arguments:*\n") + file.write("\n|===\n") + file.write("|Argument|Type|Name|Shape|Description\n\n") + for arg in op.arguments: + cats = arg.categories + if len(cats) > 1: + cattext = "" + sep = "" + for cat in cats: + proflist = "/".join(cat.profiles) + profcaption = "profiles" if len(cat.profiles) > 1 else "profile" + cattext += sep + cat.name.title() + f" ({proflist} {profcaption})" + sep = " " + else: + cattext = cats[0].name.title() + file.write( + f"|{cattext}|{arg.type}|{arg.name}|{arg.shape}|{arg.description}\n" + ) + file.write("|===\n") + if op.typesupports: + file.write("\n*Supported Data Types:*\n\n") + file.write("|===\n") + header = "|Profile|Mode" + for ty in op.types: + header += f"|{ty}" + file.write(header) + file.write("\n\n") + for tysup in op.typesupports: + profile = ", ".join(tysup.profiles) if tysup.profiles else "Any" + entry = f"|{profile}|{tysup.mode}" + for ty in op.types: + entry += f"|{tysup.tymap[ty]}" + entry += "\n" + file.write(entry) + file.write("|===\n") + + def generate(self, outdir): + opdir = os.path.join(outdir, "operators") + os.makedirs(opdir, exist_ok=True) + for group in self.spec.operatorgroups: + for op in group.operators: + with open(os.path.join(opdir, op.name + ".adoc"), "w") as f: + self.generate_operator(op, f) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument("--xml", required=True, help="Path to specification XML") + parser.add_argument("--outdir", required=True, help="Output directory") + args = parser.parse_args() + + spec = tosa.TOSASpec(args.xml) + + generator = TOSASpecAsciidocGenerator(spec) + generator.generate(args.outdir) -- cgit v1.2.1