aboutsummaryrefslogtreecommitdiff
path: root/tools/genspec.py
diff options
context:
space:
mode:
authorEric Kunze <eric.kunze@arm.com>2022-08-05 15:40:12 -0700
committerEric Kunze <eric.kunze@arm.com>2022-08-19 14:19:28 -0700
commit58098a7b1ffcf41da759f862deb753c82fe5b4b0 (patch)
tree75b61a482e23293b8af85adf6210f2d3e4e5695d /tools/genspec.py
parent6361d1664c7b82ecc3afdd0eb87e96afea430f89 (diff)
downloadspecification-58098a7b1ffcf41da759f862deb753c82fe5b4b0.tar.gz
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 <eric.kunze@arm.com>
Diffstat (limited to 'tools/genspec.py')
-rwxr-xr-xtools/genspec.py68
1 files changed, 68 insertions, 0 deletions
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)