1 /*
   2  * Copyright (c) 2014, 2018, 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 
  24 
  25 package org.graalvm.compiler.core.match;
  26 
  27 import java.lang.annotation.ElementType;
  28 import java.lang.annotation.Repeatable;
  29 import java.lang.annotation.Retention;
  30 import java.lang.annotation.RetentionPolicy;
  31 import java.lang.annotation.Target;
  32 
  33 import org.graalvm.compiler.nodes.ConstantNode;
  34 
  35 /**
  36  * This annotation declares a textual pattern for matching an HIR tree. The format is a LISP style
  37  * s-expression with node types and/or names that are matched against the HIR. Node types are always
  38  * uppercase and the names of nodes are always lowercase. Named nodes can be used to match trees
  39  * where a node is used multiple times but only as an input to the full match.
  40  *
  41  * <pre>
  42  *   &lt;node-name&gt;    := [a-z][a-zA-Z0-9]*
  43  *   &lt;node-type&gt;    := [A-Z][a-zA-Z0-9]*
  44  *   &lt;node-spec&gt;    := &lt;node-type&gt; { '=' &lt;node-name&gt; }
  45  *   &lt;node-or-name&gt; := &lt;node-spec&gt; | &lt;node-name&gt;
  46  *   &lt;argument&gt;     := &lt;node-or-name&gt; | &lt;match-rule&gt;
  47  *   &lt;match-rule&gt;   := '(' &lt;node-spec&gt; &lt;argument&gt;+ ')'
  48  * </pre>
  49  *
  50  * All matched nodes except the root of the match and {@link ConstantNode}s must have a single user.
  51  * All matched nodes must be in the same block.
  52  */
  53 
  54 @Retention(RetentionPolicy.RUNTIME)
  55 @Target(ElementType.METHOD)
  56 @Repeatable(value = MatchRules.class)
  57 public @interface MatchRule {
  58     String value();
  59 }