Mesa (master): genxml: factor out utility functions
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat May 9 07:31:43 UTC 2020
Module: Mesa
Branch: master
Commit: 942d4538a46c3420570ccf5c5f5677380c75caf0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=942d4538a46c3420570ccf5c5f5677380c75caf0
Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date: Thu Apr 30 15:43:01 2020 +0300
genxml: factor out utility functions
v2: Use the regexp version (Jordan)
Also fix regexp that missed the ' character replacement (Lionel)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4938>
---
src/intel/genxml/gen_bits_header.py | 13 +------------
src/intel/genxml/gen_pack_header.py | 35 +---------------------------------
src/intel/genxml/util.py | 38 +++++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 46 deletions(-)
diff --git a/src/intel/genxml/gen_bits_header.py b/src/intel/genxml/gen_bits_header.py
index 3b0f9ab2f3f..2bc956f39dd 100644
--- a/src/intel/genxml/gen_bits_header.py
+++ b/src/intel/genxml/gen_bits_header.py
@@ -25,10 +25,10 @@ from __future__ import (
import argparse
import os
-import re
import xml.parsers.expat
from mako.template import Template
+from util import *
TEMPLATE = Template("""\
<%!
@@ -132,17 +132,6 @@ ${emit_per_gen_prop_func(field, 'start')}
#endif /* ${guard} */""", output_encoding='utf-8')
-alphanum_nono = re.compile(r'[ /\[\]()\-:.,=>#&*"+\\]+')
-def to_alphanum(name):
- global alphanum_nono
- return alphanum_nono.sub('', name)
-
-def safe_name(name):
- name = to_alphanum(name)
- if not name[0].isalpha():
- name = '_' + name
- return name
-
class Gen(object):
def __init__(self, z):
diff --git a/src/intel/genxml/gen_pack_header.py b/src/intel/genxml/gen_pack_header.py
index 2795e5905be..0d95c4e9dd2 100644
--- a/src/intel/genxml/gen_pack_header.py
+++ b/src/intel/genxml/gen_pack_header.py
@@ -10,6 +10,7 @@ import re
import sys
import copy
import textwrap
+from util import *
license = """/*
* Copyright (C) 2016 Intel Corporation
@@ -182,40 +183,6 @@ __gen_ufixed(float v, uint32_t start, NDEBUG_UNUSED uint32_t end, uint32_t fract
"""
-def to_alphanum(name):
- substitutions = {
- ' ': '',
- '/': '',
- '[': '',
- ']': '',
- '(': '',
- ')': '',
- '-': '',
- ':': '',
- '.': '',
- ',': '',
- '=': '',
- '>': '',
- '#': '',
- '&': '',
- '*': '',
- '"': '',
- '+': '',
- '\'': '',
- }
-
- for i, j in substitutions.items():
- name = name.replace(i, j)
-
- return name
-
-def safe_name(name):
- name = to_alphanum(name)
- if not name[0].isalpha():
- name = '_' + name
-
- return name
-
def num_from_str(num_str):
if num_str.lower().startswith('0x'):
return int(num_str, base=16)
diff --git a/src/intel/genxml/util.py b/src/intel/genxml/util.py
new file mode 100644
index 00000000000..91ef622e5ae
--- /dev/null
+++ b/src/intel/genxml/util.py
@@ -0,0 +1,38 @@
+#encoding=utf-8
+#
+# Copyright © 2020 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+#
+
+# A few utility functions reused across genxml scripts
+
+import re
+
+alphanum_nono = re.compile(r'[ /\[\]()\-:.,=>#&*\'"+\\]+')
+def to_alphanum(name):
+ global alphanum_nono
+ return alphanum_nono.sub('', name)
+
+def safe_name(name):
+ name = to_alphanum(name)
+ if not name[0].isalpha():
+ name = '_' + name
+ return name
More information about the mesa-commit
mailing list