Compare commits

...

1 Commits

Author SHA1 Message Date
Harmen Stoppels
8b020067f4 spec.py: further arch related fixes 2025-01-28 16:59:53 +01:00

View File

@ -230,7 +230,7 @@ def ensure_modern_format_string(fmt: str) -> None:
def _make_microarchitecture(name: str) -> archspec.cpu.Microarchitecture: def _make_microarchitecture(name: str) -> archspec.cpu.Microarchitecture:
if isinstance(name, archspec.cpu.Microarchitecture): if isinstance(name, archspec.cpu.Microarchitecture):
return name return name
return archspec.cpu.TARGETS.get(name, archspec.cpu.generic_microarchitecture(name)) return archspec.cpu.TARGETS.get(name) or archspec.cpu.generic_microarchitecture(name)
@lang.lazy_lexicographic_ordering @lang.lazy_lexicographic_ordering
@ -467,10 +467,10 @@ def _target_constrain(self, other: "ArchSpec") -> bool:
if not other._target_satisfies(self, strict=False): if not other._target_satisfies(self, strict=False):
raise UnsatisfiableArchitectureSpecError(self, other) raise UnsatisfiableArchitectureSpecError(self, other)
if self.target_concrete: if self._target_concrete:
return False return False
elif other.target_concrete: elif other._target_concrete:
self.target = other.target self.target = other.target
return True return True
@ -485,8 +485,8 @@ def _target_constrain(self, other: "ArchSpec") -> bool:
self.target = intersection_target self.target = intersection_target
return True return True
def _target_intersection(self, other): def _target_intersection(self, other: "ArchSpec") -> List[str]:
results = [] results: List[str] = []
if not self.target or not other.target: if not self.target or not other.target:
return results return results
@ -593,23 +593,23 @@ def constrain(self, other: "ArchSpec") -> bool:
return constrained return constrained
def copy(self): def copy(self) -> "ArchSpec":
"""Copy the current instance and returns the clone.""" """Copy the current instance and returns the clone."""
return ArchSpec(self) return ArchSpec(self)
@property @property
def concrete(self): def concrete(self):
"""True if the spec is concrete, False otherwise""" """True if the spec is concrete, False otherwise"""
return self.platform and self.os and self.target and self.target_concrete return self.platform and self.os and self.target and self._target_concrete
@property @property
def target_concrete(self): def _target_concrete(self) -> bool:
"""True if the target is not a range or list.""" """True if the target is not a range or list."""
return ( return (
self.target is not None and ":" not in str(self.target) and "," not in str(self.target) self.target is not None and ":" not in str(self.target) and "," not in str(self.target)
) )
def to_dict(self): def to_dict(self) -> dict:
# Generic targets represent either an architecture family (like x86_64) # Generic targets represent either an architecture family (like x86_64)
# or a custom micro-architecture # or a custom micro-architecture
if self.target.vendor == "generic": if self.target.vendor == "generic":
@ -621,7 +621,7 @@ def to_dict(self):
return {"arch": {"platform": self.platform, "platform_os": self.os, "target": target_data}} return {"arch": {"platform": self.platform, "platform_os": self.os, "target": target_data}}
@staticmethod @staticmethod
def from_dict(d): def from_dict(d: dict) -> "ArchSpec":
"""Import an ArchSpec from raw YAML/JSON data""" """Import an ArchSpec from raw YAML/JSON data"""
arch = d["arch"] arch = d["arch"]
target_name = arch["target"] target_name = arch["target"]
@ -631,13 +631,12 @@ def from_dict(d):
return ArchSpec((arch["platform"], arch["platform_os"], target)) return ArchSpec((arch["platform"], arch["platform_os"], target))
def __str__(self): def __str__(self):
return "%s-%s-%s" % (self.platform, self.os, self.target) return f"{self.platform}-{self.os}-{self.target}"
def __repr__(self): def __repr__(self):
fmt = "ArchSpec(({0.platform!r}, {0.os!r}, {1!r}))" return f"ArchSpec(({self.platform!r}, {self.os!r}, {str(self.target)!r}))"
return fmt.format(self, str(self.target))
def __contains__(self, string): def __contains__(self, string) -> bool:
return string in str(self) or string in self.target return string in str(self) or string in self.target