Synchronize InstructionFormat and InstructionData.

These two enums must have identical variants. One is generated from the
instruction formats in meta/cretonne/formats.py, the other defines the contents
of an instruction.

Emit a conversion from InstructionData to InstructionFormat which also serves
to verify the correspondence. Rustc will error is the match is not complete.
This commit is contained in:
Jakob Stoklund Olesen
2016-05-13 14:27:24 -07:00
parent 62ecbc7448
commit e735836383
4 changed files with 67 additions and 2 deletions

View File

@@ -55,6 +55,17 @@ value = OperandKind(
operand.
""")
#: A variable-sizes list of value operands. Use for Ebb and function call
#: arguemnts.
args = OperandKind(
'args', """
A variable size list of `value` operands.
Use this to represent arguemtns passed to a function call, arguments
passed to an extended basic block, or a variable number of results
returned from an instruction.
""")
# Instances of immediate operand types are provided in the cretonne.immediates
# module.

View File

@@ -7,9 +7,11 @@ in this module.
"""
from . import InstructionFormat, value
from . import InstructionFormat, value, args
from immediates import imm64, ieee32, ieee64, immvector
Nullary = InstructionFormat()
Unary = InstructionFormat(value)
UnaryImm = InstructionFormat(imm64)
UnaryIeee32 = InstructionFormat(ieee32)
@@ -20,6 +22,7 @@ Binary = InstructionFormat(value, value)
BinaryImm = InstructionFormat(value, imm64)
BinaryImmRev = InstructionFormat(imm64, value)
Call = InstructionFormat(args, multiple_results=True)
# Finally extract the names of global variables in this module.
InstructionFormat.extract_names(globals())

View File

@@ -21,6 +21,20 @@ def gen_formats(fmt):
fmt.line(f.name + ',')
fmt.line()
# Emit a From<InstructionData> which also serves to verify that
# InstructionFormat and InstructionData are in sync.
with fmt.indented(
"impl<'a> From<&'a InstructionData> for InstructionFormat {", '}'):
with fmt.indented(
"fn from(inst: &'a InstructionData) -> InstructionFormat {",
'}'):
with fmt.indented('match *inst {', '}'):
for f in cretonne.InstructionFormat.all_formats:
fmt.line(('InstructionData::{} {{ .. }} => ' +
'InstructionFormat::{},')
.format(f.name, f.name))
fmt.line()
def collect_instr_groups(targets):
seen = set()