From 1b594717f4afcf9c39304881a190d2d32aa33fd2 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Fri, 6 Jan 2017 08:47:48 -0700 Subject: scripts: Handle vk.xml latexmath in helper files The vk.xml file contains latex-formatted metadata which must be parsed for codegen. Change-Id: Ie64c9974371d2bb66ba460165a0c23505991ebd7 --- scripts/helper_file_generator.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'scripts') diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py index 89d0788c..e64dd8a7 100644 --- a/scripts/helper_file_generator.py +++ b/scripts/helper_file_generator.py @@ -190,6 +190,24 @@ class HelperFileOutputGenerator(OutputGenerator): elif elem.tag == 'name': name = noneStr(elem.text) return (type, name) + # Extract length values from latexmath. Currently an inflexible solution that looks for specific + # patterns that are found in vk.xml. Will need to be updated when new patterns are introduced. + def parseLateXMath(self, source): + name = 'ERROR' + decoratedName = 'ERROR' + if 'mathit' in source: + # Matches expressions similar to 'latexmath:[$\lceil{\mathit{rasterizationSamples} \over 32}\rceil$]' + match = re.match(r'latexmath\s*\:\s*\[\s*\$\\l(\w+)\s*\{\s*\\mathit\s*\{\s*(\w+)\s*\}\s*\\over\s*(\d+)\s*\}\s*\\r(\w+)\$\s*\]', source) + if not match or match.group(1) != match.group(4): + raise 'Unrecognized latexmath expression' + name = match.group(2) + decoratedName = '{}/{}'.format(*match.group(2, 3)) + else: + # Matches expressions similar to 'latexmath : [$dataSize \over 4$]' + match = re.match(r'latexmath\s*\:\s*\[\s*\$\s*(\w+)\s*\\over\s*(\d+)\s*\$\s*\]', source) + name = match.group(1) + decoratedName = '{}/{}'.format(*match.group(1, 2)) + return name, decoratedName # # Retrieve the value of the len tag def getLen(self, param): @@ -203,6 +221,9 @@ class HelperFileOutputGenerator(OutputGenerator): result = len.split(',')[0] else: result = len + if 'latexmath' in len: + param_type, param_name = self.getTypeNameTuple(param) + len_name, result = self.parseLateXMath(len) # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol result = str(result).replace('::', '->') return result -- cgit v1.2.3