1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.match;
  24 
  25 import java.lang.annotation.ElementType;
  26 import java.lang.annotation.Repeatable;
  27 import java.lang.annotation.Retention;
  28 import java.lang.annotation.RetentionPolicy;
  29 import java.lang.annotation.Target;
  30 
  31 import org.graalvm.compiler.nodes.ConstantNode;
  32 
  33 /**
  34  * This annotation declares a textual pattern for matching an HIR tree. The format is a LISP style
  35  * s-expression with node types and/or names that are matched against the HIR. Node types are always
  36  * uppercase and the names of nodes are always lowercase. Named nodes can be used to match trees
  37  * where a node is used multiple times but only as an input to the full match.
  38  *
  39  * <pre>
  40  *   &lt;node-name&gt;    := [a-z][a-zA-Z0-9]*
  41  *   &lt;node-type&gt;    := [A-Z][a-zA-Z0-9]*
  42  *   &lt;node-spec&gt;    := &lt;node-type&gt; { '=' &lt;node-name&gt; }
  43  *   &lt;node-or-name&gt; := &lt;node-spec&gt; | &lt;node-name&gt;
  44  *   &lt;argument&gt;     := &lt;node-or-name&gt; | &lt;match-rule&gt;
  45  *   &lt;match-rule&gt;   := '(' &lt;node-spec&gt; &lt;argument&gt;+ ')'
  46  * </pre>
  47  *
  48  * All matched nodes except the root of the match and {@link ConstantNode}s must have a single user.
  49  * All matched nodes must be in the same block.
  50  */
  51 
  52 @Retention(RetentionPolicy.RUNTIME)
  53 @Target(ElementType.METHOD)
  54 @Repeatable(value = MatchRules.class)
  55 public @interface MatchRule {
  56     String value();
  57 }