Port simd.check() to typed_pos_args/typed_kwargs

pull/12331/head
Tristan Partin 2 years ago committed by Eli Schwartz
parent 84b8d257e4
commit a3d287c553
  1. 77
      mesonbuild/modules/simd.py

@ -13,53 +13,78 @@
# limitations under the License. # limitations under the License.
from __future__ import annotations from __future__ import annotations
from .. import mesonlib, compilers, mlog import typing as T
from .. import mesonlib, mlog
from .. import build from .. import build
from ..compilers import Compiler
from ..interpreter.type_checking import BT_SOURCES_KW, STATIC_LIB_KWS
from ..interpreterbase.decorators import KwargInfo, typed_pos_args, typed_kwargs
from . import ExtensionModule, ModuleInfo from . import ExtensionModule, ModuleInfo
if T.TYPE_CHECKING:
from ..interpreter import kwargs as kwtypes
from ..interpreter.type_checking import SourcesVarargsType
class CheckKw(kwtypes.StaticLibrary):
compiler: Compiler
mmx: SourcesVarargsType
sse: SourcesVarargsType
sse2: SourcesVarargsType
sse3: SourcesVarargsType
ssse3: SourcesVarargsType
sse41: SourcesVarargsType
sse42: SourcesVarargsType
avx: SourcesVarargsType
avx2: SourcesVarargsType
neon: SourcesVarargsType
# FIXME add Altivec and AVX512.
ISETS = (
'mmx',
'sse',
'sse2',
'sse3',
'ssse3',
'sse41',
'sse42',
'avx',
'avx2',
'neon',
)
class SimdModule(ExtensionModule): class SimdModule(ExtensionModule):
INFO = ModuleInfo('SIMD', '0.42.0', unstable=True) INFO = ModuleInfo('SIMD', '0.42.0', unstable=True)
def __init__(self, interpreter): def __init__(self, interpreter):
super().__init__(interpreter) super().__init__(interpreter)
# FIXME add Altivec and AVX512.
self.isets = ('mmx',
'sse',
'sse2',
'sse3',
'ssse3',
'sse41',
'sse42',
'avx',
'avx2',
'neon',
)
self.methods.update({ self.methods.update({
'check': self.check, 'check': self.check,
}) })
def check(self, state, args, kwargs): @typed_pos_args('simd.check', str)
result = [] @typed_kwargs('simd.check',
if len(args) != 1: KwargInfo('compiler', Compiler, required=True),
raise mesonlib.MesonException('Check requires one argument, a name prefix for checks.') *[BT_SOURCES_KW.evolve(name=iset) for iset in ISETS],
prefix = args[0] *[a for a in STATIC_LIB_KWS if a.name != 'sources'],
if not isinstance(prefix, str): allow_unknown=True) # Because we also accept STATIC_LIB_KWS, but build targets have not been completely ported to typed_pos_args/typed_kwargs.
raise mesonlib.MesonException('Argument must be a string.') def check(self, state, args: T.Tuple[str], kwargs: CheckKw):
if 'compiler' not in kwargs: result: T.List[build.StaticLibrary] = []
raise mesonlib.MesonException('Must specify compiler keyword')
if 'sources' in kwargs: if 'sources' in kwargs:
raise mesonlib.MesonException('SIMD module does not support the "sources" keyword') raise mesonlib.MesonException('SIMD module does not support the "sources" keyword')
prefix = args[0]
basic_kwargs = {} basic_kwargs = {}
for key, value in kwargs.items(): for key, value in kwargs.items():
if key not in self.isets and key != 'compiler': if key not in ISETS and key != 'compiler':
basic_kwargs[key] = value basic_kwargs[key] = value
compiler = kwargs['compiler'] compiler = kwargs['compiler']
if not isinstance(compiler, compilers.compilers.Compiler):
raise mesonlib.MesonException('Compiler argument must be a compiler object.')
conf = build.ConfigurationData() conf = build.ConfigurationData()
for iset in self.isets: for iset in ISETS:
if iset not in kwargs: if iset not in kwargs:
continue continue
iset_fname = kwargs[iset] # Might also be an array or Files. static_library will validate. iset_fname = kwargs[iset] # Might also be an array or Files. static_library will validate.

Loading…
Cancel
Save