Add a CPUMode meta-language class.

This commit is contained in:
Jakob Stoklund Olesen
2016-08-03 11:20:13 -07:00
parent bd72439fbc
commit c4faef196e
3 changed files with 24 additions and 1 deletions

View File

@@ -228,6 +228,8 @@ instruction. Both RISC-V and ARMv8's T32 mode have 32-bit encodings of all
instructions with 16-bit encodings available for some opcodes if certain instructions with 16-bit encodings available for some opcodes if certain
constraints are satisfied. constraints are satisfied.
.. autoclass:: CPUMode
Encodings are guarded by :term:`sub-target predicate`\s. For example, the RISC-V Encodings are guarded by :term:`sub-target predicate`\s. For example, the RISC-V
"C" extension which specifies the compressed encodings may not be supported, and "C" extension which specifies the compressed encodings may not be supported, and
a predicate would be used to disable all of the 16-bit encodings in that case. a predicate would be used to disable all of the 16-bit encodings in that case.

View File

@@ -656,6 +656,23 @@ class Target(object):
self.name = name self.name = name
self.instruction_groups = instrution_groups self.instruction_groups = instrution_groups
class CPUMode(object):
"""
A CPU mode determines which instruction encodings are active.
All instruction encodings are associated with exactly one `CPUMode`, and
all CPU modes are associated with exactly one `Target`.
:param name: Short mnemonic name for the CPU mode.
:param target: Associated `Target`.
"""
def __init__(self, name, target):
self.name = name
self.target = target
# Import the fixed instruction formats now so they can be added to the # Import the fixed instruction formats now so they can be added to the
# registry. # registry.
importlib.import_module('cretonne.formats') importlib.import_module('cretonne.formats')

View File

@@ -25,7 +25,11 @@ RV32G / RV64G
""" """
from cretonne import Target from cretonne import Target, CPUMode
import cretonne.base import cretonne.base
target = Target('riscv', [cretonne.base.instructions]) target = Target('riscv', [cretonne.base.instructions])
# CPU modes for 32-bit and 64-bit operation.
RV32 = CPUMode('RV32', target)
RV64 = CPUMode('RV64', target)