001/* 002 * Copyright (c) 2010, 2014, 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.lir; 024 025import jdk.internal.jvmci.code.*; 026import jdk.internal.jvmci.meta.*; 027 028/** 029 * Represents a value that is yet to be bound to a machine location (such as a {@link RegisterValue} 030 * or {@link StackSlot}) by a register allocator. 031 */ 032public final class Variable extends AllocatableValue { 033 034 /** 035 * The identifier of the variable. This is a non-zero index in a contiguous 0-based name space. 036 */ 037 public final int index; 038 039 private String name; 040 041 /** 042 * Creates a new variable. 043 * 044 * @param kind 045 * @param index 046 */ 047 public Variable(LIRKind kind, int index) { 048 super(kind); 049 assert index >= 0; 050 this.index = index; 051 } 052 053 public void setName(String name) { 054 this.name = name; 055 } 056 057 public String getName() { 058 return name; 059 } 060 061 @Override 062 public String toString() { 063 if (name != null) { 064 return name; 065 } else { 066 return "v" + index + getKindSuffix(); 067 } 068 } 069 070 @Override 071 public int hashCode() { 072 return 71 * super.hashCode() + index; 073 } 074 075 @Override 076 public boolean equals(Object obj) { 077 if (obj instanceof Variable) { 078 Variable other = (Variable) obj; 079 return super.equals(other) && index == other.index; 080 } 081 return false; 082 } 083}