Mercurial > hg > truffle
changeset 21382:e4a2ebb47271
Add utility method to remove a phase with a given class
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 14 May 2015 16:08:21 -0700 |
parents | d339bcb65015 |
children | 5cd0166c1b25 |
files | graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Thu May 14 16:06:42 2015 -0700 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Thu May 14 16:08:21 2015 -0700 @@ -70,6 +70,31 @@ return false; } + /** + * Removes the first instance of the given phase class, looking recursively into inner phase + * suites. + */ + public boolean removePhase(Class<? extends BasePhase<? super C>> phaseClass) { + ListIterator<BasePhase<? super C>> it = phases.listIterator(); + while (it.hasNext()) { + BasePhase<? super C> phase = it.next(); + if (phaseClass.isInstance(phase)) { + it.remove(); + return true; + } else if (phase instanceof PhaseSuite) { + @SuppressWarnings("unchecked") + PhaseSuite<C> innerSuite = (PhaseSuite<C>) phase; + if (innerSuite.removePhase(phaseClass)) { + if (innerSuite.phases.isEmpty()) { + it.remove(); + } + return true; + } + } + } + return false; + } + @Override protected void run(StructuredGraph graph, C context) { for (BasePhase<? super C> phase : phases) {