1 /* 2 * Copyright (c) 2009, 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.common.spi; 26 27 import java.util.Arrays; 28 29 /** 30 * The name and signature of a foreign call. A foreign call differs from a normal compiled Java call 31 * in at least one of these aspects: 32 * <ul> 33 * <li>The call is to C/C++/assembler code.</li> 34 * <li>The call uses different conventions for passing parameters or returning values.</li> 35 * <li>The callee has different register saving semantics. For example, the callee may save all 36 * registers (apart from some specified temporaries) in which case the register allocator doesn't 37 * not need to spill all live registers around the call site.</li> 38 * <li>The call does not occur at an INVOKE* bytecode. Such a call could be transformed into a 39 * standard Java call if the foreign routine is a normal Java method and the runtime supports 40 * linking Java calls at arbitrary bytecodes.</li> 41 * </ul> 42 */ 43 public class ForeignCallDescriptor { 44 45 private final String name; 46 private final Class<?> resultType; 47 private final Class<?>[] argumentTypes; 48 49 public ForeignCallDescriptor(String name, Class<?> resultType, Class<?>... argumentTypes) { 50 this.name = name; 51 this.resultType = resultType; 52 this.argumentTypes = argumentTypes; 53 } 54 55 /** 56 * Gets the name of this foreign call. 57 */ 58 public String getName() { 59 return name; 60 } 61 62 /** 63 * Gets the return type of this foreign call. 64 */ 65 public Class<?> getResultType() { 66 return resultType; 67 } 68 69 /** 70 * Gets the argument types of this foreign call. 71 */ 72 public Class<?>[] getArgumentTypes() { 73 return argumentTypes.clone(); 74 } 75 76 @Override 77 public int hashCode() { 78 return name.hashCode(); 79 } 80 81 @Override 82 public boolean equals(Object obj) { 83 if (obj instanceof ForeignCallDescriptor) { 84 ForeignCallDescriptor other = (ForeignCallDescriptor) obj; 85 return other.name.equals(name) && other.resultType.equals(resultType) && Arrays.equals(other.argumentTypes, argumentTypes); 86 } 87 return false; 88 } 89 90 @Override 91 public String toString() { 92 StringBuilder sb = new StringBuilder(name).append('('); 93 String sep = ""; 94 for (Class<?> arg : argumentTypes) { 95 sb.append(sep).append(arg.getSimpleName()); 96 sep = ","; 97 } 98 return sb.append(')').append(resultType.getSimpleName()).toString(); 99 } 100 }