gnss-sdr/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py

93 lines
3.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2014-09-07 23:56:09 +00:00
#
# Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
2014-09-07 23:56:09 +00:00
#
# This file is part of GNSS-SDR.
#
# GNSS-SDR is free software: you can redistribute it and/or modify
2014-09-07 23:56:09 +00:00
# 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.
#
# GNSS-SDR is distributed in the hope that it will be useful,
2014-09-07 23:56:09 +00:00
# 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 GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
2014-09-07 23:56:09 +00:00
#
2016-12-25 14:44:45 +00:00
from __future__ import print_function
import six
2014-09-07 23:56:09 +00:00
archs = list()
arch_dict = dict()
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
########################################################################
# 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
2017-11-15 00:23:05 +00:00
if name not in flags: flags[name] = list()
2014-09-07 23:56:09 +00:00
flags[name].append(flag_xml.firstChild.data)
#force kwargs keys to be of type str, not unicode for py25
2016-12-25 14:44:45 +00:00
kwargs = dict((str(k), v) for k, v in six.iteritems(kwargs))
2014-09-07 23:56:09 +00:00
register_arch(flags=flags, checks=checks, **kwargs)
if __name__ == '__main__':
2016-12-25 14:44:45 +00:00
print(archs)