# HG changeset patch # User Christian Wimmer # Date 1400637174 25200 # Node ID 1891bac562d8ae3f6e9837a07bcb774108b0939c # Parent 4fd787b04c928c5ac59f0d8027c086ef567e9acf Factor out rule creation in its own method diff -r 4fd787b04c92 -r 1891bac562d8 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java Tue May 20 18:51:54 2014 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java Tue May 20 18:52:54 2014 -0700 @@ -95,31 +95,7 @@ if (result == null) { NodeClassLookup lookup = new DefaultNodeClassLookup(); - HashMap, List> localRules = new HashMap<>(); - ServiceLoader sl = ServiceLoader.loadInstalled(MatchStatementSet.class); - for (MatchStatementSet rules : sl) { - localRules.put(rules.forClass(), rules.statements(lookup)); - } - - // Walk the class hierarchy collecting lists and merge them together. The subclass - // rules are first which gives them preference over earlier rules. - Map, List> rules = new HashMap<>(); - Class currentClass = theClass; - do { - List statements = localRules.get(currentClass); - if (statements != null) { - for (MatchStatement statement : statements) { - Class nodeClass = statement.getPattern().nodeClass(); - List current = rules.get(nodeClass); - if (current == null) { - current = new ArrayList<>(); - rules.put(nodeClass, current); - } - current.add(statement); - } - } - currentClass = currentClass.getSuperclass(); - } while (currentClass != NodeLIRBuilder.class); + Map, List> rules = createRules(theClass, lookup); registry.put(theClass, rules); assert registry.get(theClass) == rules; result = rules; @@ -142,4 +118,38 @@ } return result; } + + /* + * This is a separate, public method so that external clients can create rules with a custom + * lookup and without the default caching behavior. + */ + public static Map, List> createRules(Class theClass, NodeClassLookup lookup) { + HashMap, MatchStatementSet> matchSets = new HashMap<>(); + ServiceLoader sl = ServiceLoader.loadInstalled(MatchStatementSet.class); + for (MatchStatementSet rules : sl) { + matchSets.put(rules.forClass(), rules); + } + + // Walk the class hierarchy collecting lists and merge them together. The subclass + // rules are first which gives them preference over earlier rules. + Map, List> rules = new HashMap<>(); + Class currentClass = theClass; + do { + MatchStatementSet matchSet = matchSets.get(currentClass); + if (matchSet != null) { + List statements = matchSet.statements(lookup); + for (MatchStatement statement : statements) { + Class nodeClass = statement.getPattern().nodeClass(); + List current = rules.get(nodeClass); + if (current == null) { + current = new ArrayList<>(); + rules.put(nodeClass, current); + } + current.add(statement); + } + } + currentClass = currentClass.getSuperclass(); + } while (currentClass != NodeLIRBuilder.class); + return rules; + } }