summaryrefslogtreecommitdiff
path: root/volk/gen/volk_arch_defs.py
diff options
context:
space:
mode:
authorBen Reynwar2012-04-30 09:20:59 -0700
committerBen Reynwar2012-04-30 09:20:59 -0700
commit2817cf14147d6da2e7ef051fbbbf8228fd1c07ba (patch)
tree0695ce3bcdbd75784198c28e6cb963c99ae5d0f6 /volk/gen/volk_arch_defs.py
parente7f45e3c513242706a9e4aa36e99e33e79e66d4f (diff)
parentd7ecbd12be995ad6db7a53a5d6dd3fcb205c07ea (diff)
downloadgnuradio-2817cf14147d6da2e7ef051fbbbf8228fd1c07ba.tar.gz
gnuradio-2817cf14147d6da2e7ef051fbbbf8228fd1c07ba.tar.bz2
gnuradio-2817cf14147d6da2e7ef051fbbbf8228fd1c07ba.zip
Merge branch 'master' of http://gnuradio.org/git/gnuradio
Diffstat (limited to 'volk/gen/volk_arch_defs.py')
-rw-r--r--volk/gen/volk_arch_defs.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/volk/gen/volk_arch_defs.py b/volk/gen/volk_arch_defs.py
new file mode 100644
index 000000000..41154d5a7
--- /dev/null
+++ b/volk/gen/volk_arch_defs.py
@@ -0,0 +1,92 @@
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+archs = list()
+arch_dict = dict()
+
+#TODO enable this when we are ready
+create_unaligned_archs = False
+
+class arch_class:
+ def __init__(self, flags, checks, **kwargs):
+ for key, cast, failval in (
+ ('name', str, None),
+ ('environment', str, None),
+ ('include', str, None),
+ ('alignment', int, 1)
+ ):
+ try: setattr(self, key, cast(kwargs[key]))
+ except: setattr(self, key, failval)
+ self.checks = checks
+ assert(self.name)
+ self._flags = flags
+
+ def is_supported(self, compiler):
+ if not self._flags.keys(): return True
+ return compiler in self._flags.keys()
+
+ def get_flags(self, compiler):
+ try: return self._flags[compiler]
+ except KeyError: return list()
+
+ def __repr__(self): return self.name
+
+def register_arch(**kwargs):
+ arch = arch_class(**kwargs)
+ archs.append(arch)
+ arch_dict[arch.name] = arch
+ if arch.alignment > 1 and create_unaligned_archs:
+ kwargs['name'] += '_u'
+ kwargs['alignment'] = 1
+ register_arch(**kwargs)
+
+########################################################################
+# register the arches
+########################################################################
+#TODO skip the XML and put it here
+from xml.dom import minidom
+import os
+gendir = os.path.dirname(__file__)
+archs_xml = minidom.parse(os.path.join(gendir, 'archs.xml')).getElementsByTagName('arch')
+for arch_xml in archs_xml:
+ kwargs = dict()
+ for attr in arch_xml.attributes.keys():
+ kwargs[attr] = arch_xml.attributes[attr].value
+ for node in arch_xml.childNodes:
+ try:
+ name = node.tagName
+ val = arch_xml.getElementsByTagName(name)[0].firstChild.data
+ kwargs[name] = val
+ except: pass
+ checks = list()
+ for check_xml in arch_xml.getElementsByTagName("check"):
+ name = check_xml.attributes["name"].value
+ params = list()
+ for param_xml in check_xml.getElementsByTagName("param"):
+ params.append(param_xml.firstChild.data)
+ checks.append([name, params])
+ flags = dict()
+ for flag_xml in arch_xml.getElementsByTagName("flag"):
+ name = flag_xml.attributes["compiler"].value
+ if not flags.has_key(name): flags[name] = list()
+ flags[name].append(flag_xml.firstChild.data)
+ #force kwargs keys to be of type str, not unicode for py25
+ kwargs = dict((str(k), v) for k, v in kwargs.iteritems())
+ register_arch(flags=flags, checks=checks, **kwargs)
+
+if __name__ == '__main__':
+ print archs