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