1/*
2 * Copyright (c) 2016, 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 */
23package org.graalvm.compiler.nodes.graphbuilderconf;
24
25import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
26import org.graalvm.compiler.nodes.StructuredGraph;
27import org.graalvm.compiler.nodes.ValueNode;
28import org.graalvm.compiler.nodes.spi.StampProvider;
29
30import jdk.vm.ci.meta.Assumptions;
31import jdk.vm.ci.meta.ConstantReflectionProvider;
32import jdk.vm.ci.meta.MetaAccessProvider;
33
34/**
35 * Used by a {@link GraphBuilderPlugin} to interface with an object that builds a graph.
36 */
37public interface GraphBuilderTool {
38
39    /**
40     * Raw operation for adding a node to the graph.
41     *
42     * @return either the node added or an equivalent node
43     */
44    <T extends ValueNode> T append(T value);
45
46    /**
47     * Adds the given node to the graph and also adds recursively all referenced inputs.
48     *
49     * @param value the node to be added to the graph
50     * @return either the node added or an equivalent node
51     */
52    <T extends ValueNode> T recursiveAppend(T value);
53
54    StampProvider getStampProvider();
55
56    MetaAccessProvider getMetaAccess();
57
58    default Assumptions getAssumptions() {
59        return getGraph().getAssumptions();
60    }
61
62    ConstantReflectionProvider getConstantReflection();
63
64    ConstantFieldProvider getConstantFieldProvider();
65
66    /**
67     * Gets the graph being constructed.
68     */
69    StructuredGraph getGraph();
70
71    /**
72     * Determines if this parsing context is within the bytecode of an intrinsic or a method inlined
73     * by an intrinsic.
74     */
75    boolean parsingIntrinsic();
76}
77