Get rid of operand_kind()
This method caused lots of import cycles when type checking. Use isinstance() in the Operand constructor instead to decipher the OperandSpec union type.
This commit is contained in:
@@ -32,14 +32,6 @@ class OperandKind(object):
|
|||||||
# type: () -> str
|
# type: () -> str
|
||||||
return 'OperandKind({})'.format(self.name)
|
return 'OperandKind({})'.format(self.name)
|
||||||
|
|
||||||
def operand_kind(self):
|
|
||||||
# type: () -> OperandKind
|
|
||||||
"""
|
|
||||||
An `OperandKind` instance can be used directly as the type of an
|
|
||||||
`Operand` when defining an instruction.
|
|
||||||
"""
|
|
||||||
return self
|
|
||||||
|
|
||||||
def free_typevar(self):
|
def free_typevar(self):
|
||||||
# Return the free typevariable controlling the type of this operand.
|
# Return the free typevariable controlling the type of this operand.
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ polymorphic by using type variables.
|
|||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import math
|
import math
|
||||||
import cdsl.operands
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Tuple, Union # noqa
|
from typing import Tuple, Union # noqa
|
||||||
@@ -314,13 +313,6 @@ class TypeVar(object):
|
|||||||
|
|
||||||
return TypeVar(None, None, base=self, derived_func='DoubleWidth')
|
return TypeVar(None, None, base=self, derived_func='DoubleWidth')
|
||||||
|
|
||||||
def operand_kind(self):
|
|
||||||
# type: () -> cdsl.operands.OperandKind
|
|
||||||
# When a `TypeVar` object is used to describe the type of an `Operand`
|
|
||||||
# in an instruction definition, the kind of that operand is an SSA
|
|
||||||
# value.
|
|
||||||
return cdsl.operands.VALUE
|
|
||||||
|
|
||||||
def free_typevar(self):
|
def free_typevar(self):
|
||||||
# type: () -> TypeVar
|
# type: () -> TypeVar
|
||||||
if self.is_derived:
|
if self.is_derived:
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ from __future__ import absolute_import
|
|||||||
import importlib
|
import importlib
|
||||||
from cdsl import camel_case
|
from cdsl import camel_case
|
||||||
from cdsl.predicates import And
|
from cdsl.predicates import And
|
||||||
import cdsl.types
|
from cdsl.types import ValueType
|
||||||
|
from cdsl.typevar import TypeVar
|
||||||
from cdsl.operands import VALUE, VARIABLE_ARGS, OperandKind
|
from cdsl.operands import VALUE, VARIABLE_ARGS, OperandKind
|
||||||
|
|
||||||
# The typing module is only required by mypy, and we don't use these imports
|
# The typing module is only required by mypy, and we don't use these imports
|
||||||
@@ -18,7 +19,7 @@ try:
|
|||||||
from cdsl.predicates import Predicate, FieldPredicate # noqa
|
from cdsl.predicates import Predicate, FieldPredicate # noqa
|
||||||
MaybeBoundInst = Union['Instruction', 'BoundInstruction']
|
MaybeBoundInst = Union['Instruction', 'BoundInstruction']
|
||||||
AnyPredicate = Union['Predicate', 'FieldPredicate']
|
AnyPredicate = Union['Predicate', 'FieldPredicate']
|
||||||
OperandSpec = Union['OperandKind', 'cdsl.types.ValueType', 'TypeVar']
|
OperandSpec = Union['OperandKind', ValueType, TypeVar]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
|
|
||||||
@@ -105,10 +106,12 @@ class Operand(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.__doc__ = doc
|
self.__doc__ = doc
|
||||||
self.typ = typ
|
self.typ = typ
|
||||||
if isinstance(typ, cdsl.types.ValueType):
|
if isinstance(typ, ValueType):
|
||||||
|
self.kind = VALUE
|
||||||
|
elif isinstance(typ, TypeVar):
|
||||||
self.kind = VALUE
|
self.kind = VALUE
|
||||||
else:
|
else:
|
||||||
self.kind = typ.operand_kind()
|
self.kind = typ
|
||||||
|
|
||||||
def get_doc(self):
|
def get_doc(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
@@ -126,7 +129,7 @@ class Operand(object):
|
|||||||
"""
|
"""
|
||||||
Is this an SSA value operand?
|
Is this an SSA value operand?
|
||||||
"""
|
"""
|
||||||
return self.kind is cdsl.operands.VALUE
|
return self.kind is VALUE
|
||||||
|
|
||||||
|
|
||||||
class InstructionFormat(object):
|
class InstructionFormat(object):
|
||||||
@@ -464,7 +467,7 @@ class Instruction(object):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
def bind(self, *args):
|
def bind(self, *args):
|
||||||
# type: (*cdsl.types.ValueType) -> BoundInstruction
|
# type: (*ValueType) -> BoundInstruction
|
||||||
"""
|
"""
|
||||||
Bind a polymorphic instruction to a concrete list of type variable
|
Bind a polymorphic instruction to a concrete list of type variable
|
||||||
values.
|
values.
|
||||||
@@ -480,10 +483,10 @@ class Instruction(object):
|
|||||||
|
|
||||||
>>> iadd.i32
|
>>> iadd.i32
|
||||||
"""
|
"""
|
||||||
return self.bind(cdsl.types.ValueType.by_name(name))
|
return self.bind(ValueType.by_name(name))
|
||||||
|
|
||||||
def fully_bound(self):
|
def fully_bound(self):
|
||||||
# type: () -> Tuple[Instruction, Tuple[cdsl.types.ValueType, ...]]
|
# type: () -> Tuple[Instruction, Tuple[ValueType, ...]]
|
||||||
"""
|
"""
|
||||||
Verify that all typevars have been bound, and return a
|
Verify that all typevars have been bound, and return a
|
||||||
`(inst, typevars)` pair.
|
`(inst, typevars)` pair.
|
||||||
@@ -509,7 +512,7 @@ class BoundInstruction(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, inst, typevars):
|
def __init__(self, inst, typevars):
|
||||||
# type: (Instruction, Tuple[cdsl.types.ValueType, ...]) -> None
|
# type: (Instruction, Tuple[ValueType, ...]) -> None
|
||||||
self.inst = inst
|
self.inst = inst
|
||||||
self.typevars = typevars
|
self.typevars = typevars
|
||||||
assert len(typevars) <= 1 + len(inst.other_typevars)
|
assert len(typevars) <= 1 + len(inst.other_typevars)
|
||||||
@@ -518,7 +521,7 @@ class BoundInstruction(object):
|
|||||||
return '.'.join([self.inst.name, ] + list(map(str, self.typevars)))
|
return '.'.join([self.inst.name, ] + list(map(str, self.typevars)))
|
||||||
|
|
||||||
def bind(self, *args):
|
def bind(self, *args):
|
||||||
# type: (*cdsl.types.ValueType) -> BoundInstruction
|
# type: (*ValueType) -> BoundInstruction
|
||||||
"""
|
"""
|
||||||
Bind additional typevars.
|
Bind additional typevars.
|
||||||
"""
|
"""
|
||||||
@@ -531,10 +534,10 @@ class BoundInstruction(object):
|
|||||||
|
|
||||||
>>> uext.i32.i8
|
>>> uext.i32.i8
|
||||||
"""
|
"""
|
||||||
return self.bind(cdsl.types.ValueType.by_name(name))
|
return self.bind(ValueType.by_name(name))
|
||||||
|
|
||||||
def fully_bound(self):
|
def fully_bound(self):
|
||||||
# type: () -> Tuple[Instruction, Tuple[cdsl.types.ValueType, ...]]
|
# type: () -> Tuple[Instruction, Tuple[ValueType, ...]]
|
||||||
"""
|
"""
|
||||||
Verify that all typevars have been bound, and return a
|
Verify that all typevars have been bound, and return a
|
||||||
`(inst, typevars)` pair.
|
`(inst, typevars)` pair.
|
||||||
|
|||||||
Reference in New Issue
Block a user