Add string conversions for predicates and encodings.
This is just used for printing better comments in generated code.
This commit is contained in:
@@ -1003,6 +1003,9 @@ class EncRecipe(object):
|
||||
if instp:
|
||||
assert instp.predicate_context() == format
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Encoding(object):
|
||||
"""
|
||||
@@ -1034,6 +1037,9 @@ class Encoding(object):
|
||||
self.instp = And.combine(recipe.instp, instp)
|
||||
self.isap = And.combine(recipe.isap, instp)
|
||||
|
||||
def __str__(self):
|
||||
return '[{}/{:02x}]'.format(self.recipe, self.encbits)
|
||||
|
||||
def ctrl_typevar(self):
|
||||
"""
|
||||
Get the controlling type variable for this encoding or `None`.
|
||||
|
||||
@@ -65,6 +65,14 @@ class Predicate(object):
|
||||
(p.predicate_context() for p in 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):
|
||||
return self.context
|
||||
|
||||
@@ -164,6 +172,10 @@ class FieldPredicate(object):
|
||||
self.function = function
|
||||
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):
|
||||
"""
|
||||
This predicate can be evaluated in the context of an instruction
|
||||
|
||||
@@ -203,6 +203,8 @@ def gen_isa(cpumodes, fmt):
|
||||
for level2 in level1:
|
||||
for enclist in level2:
|
||||
fmt.comment(enclist.name())
|
||||
for enc in enclist.encodings:
|
||||
fmt.comment('{} when {}'.format(enc, enc.instp))
|
||||
|
||||
|
||||
def generate(isas, out_dir):
|
||||
|
||||
Reference in New Issue
Block a user