From 7cb975ce63b74685ba584cf98e76b60b12a10138 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 26 Aug 2016 08:50:47 -0700 Subject: [PATCH] Add string conversions for predicates and encodings. This is just used for printing better comments in generated code. --- meta/cretonne/__init__.py | 6 ++++++ meta/cretonne/predicates.py | 12 ++++++++++++ meta/gen_encoding.py | 2 ++ 3 files changed, 20 insertions(+) diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index 8dd0535b24..88860286dc 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -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`. diff --git a/meta/cretonne/predicates.py b/meta/cretonne/predicates.py index f99f4cfc5f..6722c820e5 100644 --- a/meta/cretonne/predicates.py +++ b/meta/cretonne/predicates.py @@ -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 diff --git a/meta/gen_encoding.py b/meta/gen_encoding.py index c1e618e046..a7ac7e2f4a 100644 --- a/meta/gen_encoding.py +++ b/meta/gen_encoding.py @@ -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):