Collect all instructions into instruction groups.
This commit is contained in:
@@ -72,3 +72,5 @@ class.
|
||||
|
||||
.. autoclass:: Operand
|
||||
.. autoclass:: Instruction
|
||||
.. autoclass:: InstructionGroup
|
||||
:members:
|
||||
|
||||
@@ -150,6 +150,50 @@ class ImmediateType(object):
|
||||
# Defining instructions.
|
||||
#
|
||||
|
||||
class InstructionGroup(object):
|
||||
"""
|
||||
An instruction group.
|
||||
|
||||
Every instruction must belong to exactly one instruction group. A given
|
||||
target architecture can support instructions from multiple groups, and it
|
||||
does not necessarily support all instructions in a group.
|
||||
|
||||
New instructions are automatically added to the currently open instruction
|
||||
group.
|
||||
"""
|
||||
|
||||
# The currently open instruction group.
|
||||
_current = None
|
||||
|
||||
def open(self):
|
||||
"""
|
||||
Open this instruction group such that future new instructions are
|
||||
added to this group.
|
||||
"""
|
||||
assert InstructionGroup._current is None, (
|
||||
"Can't open {} since {} is already open".format(self, _current))
|
||||
InstructionGroup._current = self
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Close this instruction group. This function should be called before
|
||||
opening another instruction group.
|
||||
"""
|
||||
assert InstructionGroup._current is self, (
|
||||
"Can't close {}, the open instuction group is {}".format(self, _current))
|
||||
InstructionGroup._current = None
|
||||
|
||||
def __init__(self, name, doc):
|
||||
self.name = name
|
||||
self.__doc__ = doc
|
||||
self.instructions = []
|
||||
self.open()
|
||||
|
||||
@staticmethod
|
||||
def append(inst):
|
||||
assert InstructionGroup._current, "Open an instruction group before defining instructions."
|
||||
InstructionGroup._current.instructions.append(inst)
|
||||
|
||||
class Operand(object):
|
||||
"""
|
||||
An instruction operand.
|
||||
@@ -202,6 +246,7 @@ class Instruction(object):
|
||||
self.__doc__ = doc
|
||||
self.ins = self._to_operand_tuple(ins)
|
||||
self.outs = self._to_operand_tuple(outs)
|
||||
InstructionGroup.append(self)
|
||||
|
||||
@staticmethod
|
||||
def _to_operand_tuple(x):
|
||||
|
||||
@@ -3,10 +3,12 @@ Cretonne base instruction set.
|
||||
|
||||
This module defines the basic Cretonne instruction set that all targets support.
|
||||
"""
|
||||
from . import TypeVar, Operand, Instruction
|
||||
from . import TypeVar, Operand, Instruction, InstructionGroup
|
||||
from types import i8, f32, f64
|
||||
from immediates import imm64, ieee32, ieee64, immvector
|
||||
|
||||
instructions = InstructionGroup("base", "Shared base instruction set")
|
||||
|
||||
Int = TypeVar('Int', 'A scalar or vector integer type')
|
||||
iB = TypeVar('iB', 'A scalar integer type')
|
||||
TxN = TypeVar('%Tx%N', 'A SIMD vector type')
|
||||
@@ -321,3 +323,5 @@ popcnt = Instruction('popcnt', r"""
|
||||
Count the number of one bits in ``x``.
|
||||
""",
|
||||
ins=x, outs=a)
|
||||
|
||||
instructions.close()
|
||||
|
||||
Reference in New Issue
Block a user