Define AST nodes and instruction transformations.
Enable syntax: iadd(x, y) which creates an Apply node. Enable syntax: z << iadd(x, y) which creates a Def node. Add an XForm class which represents source and destination patterns as RTL lists.
This commit is contained in:
@@ -10,6 +10,7 @@ import math
|
||||
import importlib
|
||||
from collections import OrderedDict
|
||||
from .predicates import And
|
||||
from .ast import Apply
|
||||
|
||||
|
||||
camel_re = re.compile('(^|_)([a-z])')
|
||||
@@ -603,6 +604,12 @@ class Operand(object):
|
||||
def __str__(self):
|
||||
return "`{}`".format(self.name)
|
||||
|
||||
def is_value(self):
|
||||
"""
|
||||
Is this an SSA value operand?
|
||||
"""
|
||||
return self.kind is value
|
||||
|
||||
|
||||
class InstructionFormat(object):
|
||||
"""
|
||||
@@ -779,10 +786,13 @@ class Instruction(object):
|
||||
self.format = InstructionFormat.lookup(self.ins, self.outs)
|
||||
# Indexes into outs for value results. Others are `variable_args`.
|
||||
self.value_results = tuple(
|
||||
i for i, o in enumerate(self.outs) if o.kind is value)
|
||||
i for i, o in enumerate(self.outs) if o.is_value())
|
||||
self._verify_polymorphic()
|
||||
InstructionGroup.append(self)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def _verify_polymorphic(self):
|
||||
"""
|
||||
Check if this instruction is polymorphic, and verify its use of type
|
||||
@@ -910,6 +920,13 @@ class Instruction(object):
|
||||
assert not self.is_polymorphic, self
|
||||
return (self, ())
|
||||
|
||||
def __call__(self, *args):
|
||||
"""
|
||||
Create an `ast.Apply` AST node representing the application of this
|
||||
instruction to the arguments.
|
||||
"""
|
||||
return Apply(self, args)
|
||||
|
||||
|
||||
class BoundInstruction(object):
|
||||
"""
|
||||
@@ -951,6 +968,13 @@ class BoundInstruction(object):
|
||||
assert len(self.typevars) == 1 + len(self.inst.other_typevars)
|
||||
return (self.inst, self.typevars)
|
||||
|
||||
def __call__(self, *args):
|
||||
"""
|
||||
Create an `ast.Apply` AST node representing the application of this
|
||||
instruction to the arguments.
|
||||
"""
|
||||
return Apply(self, args)
|
||||
|
||||
|
||||
# Defining target ISAs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user