Add string conversions for predicates and encodings.

This is just used for printing better comments in generated code.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-26 08:50:47 -07:00
parent 0c6e0e9cb7
commit 7cb975ce63
3 changed files with 20 additions and 0 deletions

View File

@@ -1003,6 +1003,9 @@ class EncRecipe(object):
if instp: if instp:
assert instp.predicate_context() == format assert instp.predicate_context() == format
def __str__(self):
return self.name
class Encoding(object): class Encoding(object):
""" """
@@ -1034,6 +1037,9 @@ class Encoding(object):
self.instp = And.combine(recipe.instp, instp) self.instp = And.combine(recipe.instp, instp)
self.isap = And.combine(recipe.isap, instp) self.isap = And.combine(recipe.isap, instp)
def __str__(self):
return '[{}/{:02x}]'.format(self.recipe, self.encbits)
def ctrl_typevar(self): def ctrl_typevar(self):
""" """
Get the controlling type variable for this encoding or `None`. Get the controlling type variable for this encoding or `None`.

View File

@@ -65,6 +65,14 @@ class Predicate(object):
(p.predicate_context() for p in parts)) (p.predicate_context() for p in parts))
assert self.context, "Incompatible predicate parts" assert self.context, "Incompatible predicate parts"
def __str__(self):
s = '{}({})'.format(
type(self).__name__,
' ,'.join(map(str, self.parts)))
if self.name:
s = '{}={}'.format(self.name, s)
return s
def predicate_context(self): def predicate_context(self):
return self.context return self.context
@@ -164,6 +172,10 @@ class FieldPredicate(object):
self.function = function self.function = function
self.args = args self.args = args
def __str__(self):
args = (self.field.name,) + tuple(map(str, self.args))
return '{}({})'.format(self.function, ', '.join(args))
def predicate_context(self): def predicate_context(self):
""" """
This predicate can be evaluated in the context of an instruction This predicate can be evaluated in the context of an instruction

View File

@@ -203,6 +203,8 @@ def gen_isa(cpumodes, fmt):
for level2 in level1: for level2 in level1:
for enclist in level2: for enclist in level2:
fmt.comment(enclist.name()) fmt.comment(enclist.name())
for enc in enclist.encodings:
fmt.comment('{} when {}'.format(enc, enc.instp))
def generate(isas, out_dir): def generate(isas, out_dir):