Support constant integers in AST expressions.

Make it possible to write AST nodes: iconst.i32(imm64(0)).
This commit is contained in:
Jakob Stoklund Olesen
2017-07-28 08:57:32 -07:00
parent ede02e0f97
commit b5076108c1
2 changed files with 49 additions and 3 deletions

View File

@@ -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
"""