Support constant integers in AST expressions.
Make it possible to write AST nodes: iconst.i32(imm64(0)).
This commit is contained in:
@@ -8,7 +8,7 @@ try:
|
||||
from typing import Union, Dict, TYPE_CHECKING # noqa
|
||||
OperandSpec = Union['OperandKind', ValueType, TypeVar]
|
||||
if TYPE_CHECKING:
|
||||
from .ast import Enumerator # noqa
|
||||
from .ast import Enumerator, ConstantInt # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -107,6 +107,20 @@ class ImmediateKind(OperandKind):
|
||||
n=self.name, a=value))
|
||||
return Enumerator(self, value)
|
||||
|
||||
def __call__(self, value):
|
||||
# type: (int) -> ConstantInt
|
||||
"""
|
||||
Create an AST node representing a constant integer:
|
||||
|
||||
iconst(imm64(0))
|
||||
"""
|
||||
from .ast import ConstantInt # noqa
|
||||
if self.values:
|
||||
raise AssertionError(
|
||||
"{}({}): Can't make a constant numeric value for an enum"
|
||||
.format(self.name, value))
|
||||
return ConstantInt(self, value)
|
||||
|
||||
def rust_enumerator(self, value):
|
||||
# type: (str) -> str
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user