From 88cbd5a43b89832f1b7fc930a0ee39fe7ed23b6c Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 2 Nov 2016 14:28:37 -0700 Subject: [PATCH] Canonicalize the objects in an RTL list. Any Apply objects in the input are converted to Defs with empty def lists. --- lib/cretonne/meta/cretonne/xform.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/cretonne/meta/cretonne/xform.py b/lib/cretonne/meta/cretonne/xform.py index 1100e4721f..5149c02991 100644 --- a/lib/cretonne/meta/cretonne/xform.py +++ b/lib/cretonne/meta/cretonne/xform.py @@ -15,12 +15,25 @@ SRCCTX = 1 DSTCTX = 2 +def canonicalize_defapply(node): + # type: (DefApply) -> Def + """ + Canonicalize a `Def` or `Apply` node into a `Def`. + + An `Apply` becomes a `Def` with an empty list of defs. + """ + if isinstance(node, Apply): + return Def((), node) + else: + return node + + class Rtl(object): """ Register Transfer Language list. An RTL object contains a list of register assignments in the form of `Def` - objects and/or Apply objects for side-effecting instructions. + objects. An RTL list can represent both a source pattern to be matched, or a destination pattern to be inserted. @@ -28,10 +41,10 @@ class Rtl(object): def __init__(self, *args): # type: (*DefApply) -> None - self.rtl = args + self.rtl = tuple(map(canonicalize_defapply, args)) def __iter__(self): - # type: () -> Iterator[DefApply] + # type: () -> Iterator[Def] return iter(self.rtl)