001/*
002 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.nodes;
024
025import java.util.*;
026
027import jdk.internal.jvmci.meta.*;
028
029import com.oracle.graal.compiler.common.type.*;
030import com.oracle.graal.graph.*;
031import com.oracle.graal.nodeinfo.*;
032import com.oracle.graal.nodes.spi.*;
033
034@NodeInfo(allowedUsageTypes = {InputType.Extension})
035public abstract class CallTargetNode extends ValueNode implements LIRLowerable {
036    public static final NodeClass<CallTargetNode> TYPE = NodeClass.create(CallTargetNode.class);
037
038    public enum InvokeKind {
039        Interface(false),
040        Special(true),
041        Static(true),
042        Virtual(false);
043
044        private InvokeKind(boolean direct) {
045            this.direct = direct;
046        }
047
048        private final boolean direct;
049
050        public boolean hasReceiver() {
051            return this != Static;
052        }
053
054        public boolean isDirect() {
055            return direct;
056        }
057
058        public boolean isIndirect() {
059            return !direct;
060        }
061
062        public boolean isInterface() {
063            return this == InvokeKind.Interface;
064        }
065    }
066
067    @Input protected NodeInputList<ValueNode> arguments;
068    protected ResolvedJavaMethod targetMethod;
069    protected InvokeKind invokeKind;
070
071    protected CallTargetNode(NodeClass<? extends CallTargetNode> c, ValueNode[] arguments, ResolvedJavaMethod targetMethod, InvokeKind invokeKind) {
072        super(c, StampFactory.forVoid());
073        this.targetMethod = targetMethod;
074        this.invokeKind = invokeKind;
075        this.arguments = new NodeInputList<>(this, arguments);
076    }
077
078    protected CallTargetNode(NodeClass<? extends CallTargetNode> c, List<ValueNode> arguments, ResolvedJavaMethod targetMethod, InvokeKind invokeKind) {
079        super(c, StampFactory.forVoid());
080        this.targetMethod = targetMethod;
081        this.invokeKind = invokeKind;
082        this.arguments = new NodeInputList<>(this, arguments);
083    }
084
085    public NodeInputList<ValueNode> arguments() {
086        return arguments;
087    }
088
089    public abstract Stamp returnStamp();
090
091    /**
092     * A human-readable representation of the target, used for debug printing only.
093     */
094    public abstract String targetName();
095
096    @Override
097    public void generate(NodeLIRBuilderTool gen) {
098        // nop
099    }
100
101    public void setTargetMethod(ResolvedJavaMethod method) {
102        targetMethod = method;
103    }
104
105    /**
106     * Gets the target method for this invocation instruction.
107     *
108     * @return the target method
109     */
110    public ResolvedJavaMethod targetMethod() {
111        return targetMethod;
112    }
113
114    public InvokeKind invokeKind() {
115        return invokeKind;
116    }
117
118    public void setInvokeKind(InvokeKind kind) {
119        this.invokeKind = kind;
120    }
121}