aboutsummaryrefslogtreecommitdiff
path: root/tools/tosa.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/tosa.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/tosa.py')
-rw-r--r--tools/tosa.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/tosa.py b/tools/tosa.py
new file mode 100644
index 0000000..87b4f1a
--- /dev/null
+++ b/tools/tosa.py
@@ -0,0 +1,97 @@
+import re
+import xml.etree.ElementTree as ET
+
+
+class TOSAOperatorArgumentCategory:
+ def __init__(self, name, profiles=None):
+ self.name = name
+ self.profiles = profiles
+
+
+class TOSAOperatorArgument:
+ def __init__(self, name, description, categories, ty, shape):
+ self.name = name
+ self.description = description
+ self.categories = categories
+ self.type = ty
+ self.shape = shape
+
+
+class TOSAOperatorDataTypeSupport:
+ def __init__(self, mode, tymap, profiles=None):
+ self.mode = mode
+ self.tymap = tymap
+ self.profiles = profiles
+
+
+class TOSAOperator:
+ def __init__(self, name, arguments, types, typesupports):
+ self.name = name
+ self.arguments = arguments
+ self.types = types
+ self.typesupports = typesupports
+
+
+class TOSAOperatorGroup:
+ def __init__(self, name, operators):
+ self.name = name
+ self.operators = operators
+
+
+class TOSASpec:
+ def __init__(self, xmlpath):
+ tree = ET.parse(xmlpath)
+ self.xmlroot = tree.getroot()
+ self.operatorgroups = []
+ self.__load_spec()
+
+ def __load_spec(self):
+ for group in self.xmlroot.findall("./operators/operatorgroup"):
+ self.operatorgroups.append(self.__load_operator_group(group))
+
+ def __load_operator_group(self, group):
+ name = group.get("name")
+ operators = []
+ for op in group.findall("operator"):
+ operators.append(self.__load_operator(op))
+ return TOSAOperatorGroup(name, operators)
+
+ def __load_operator(self, op):
+ name = op.find("name").text
+ args = []
+ types = []
+ typesupports = []
+ for arg in op.findall("arguments/argument"):
+ args.append(self.__load_operator_argument(arg))
+
+ # TODO add pseudo-code to operator object?
+
+ for ty in op.findall("types/type"):
+ types.append(ty.get("name"))
+
+ for tysup in op.findall("typesupport"):
+ tsmode = tysup.get("mode")
+ tsmap = {}
+ profiles = tysup.findall("profile")
+ tsprofiles = []
+ for p in profiles:
+ tsprofiles.append(p.get("name"))
+ for ty in types:
+ tsmap[ty] = tysup.get(ty)
+ typesupports.append(TOSAOperatorDataTypeSupport(tsmode, tsmap, tsprofiles))
+ return TOSAOperator(name, args, types, typesupports)
+
+ def __load_operator_argument(self, arg):
+ name = arg.get("name")
+ desc = arg.find("description").text.strip()
+ argcats = []
+ argtype = arg.get("type")
+ shape = arg.get("shape")
+
+ cats = re.findall(
+ r"(input|output|attribute)\(?([A-Z,]+)?\)?", arg.get("category")
+ )
+ for cat in cats:
+ argcats.append(TOSAOperatorArgumentCategory(cat[0], cat[1].split(",")))
+
+ return TOSAOperatorArgument(name, desc, argcats, argtype, shape)