Mercurial > hg > truffle
comparison graal/Runtime/src/com/sun/hotspot/c1x/HotSpotSignature.java @ 2297:099e697d8934
Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:08:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2296:34354e2e40a3 | 2297:099e697d8934 |
---|---|
1 /* | |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product | |
5 * that is described in this document. In particular, and without limitation, these intellectual property | |
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or | |
7 * more additional patents or pending patent applications in the U.S. and in other countries. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun | |
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its | |
11 * supplements. | |
12 * | |
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or | |
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks | |
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the | |
16 * U.S. and other countries. | |
17 * | |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | |
19 * Company, Ltd. | |
20 */ | |
21 package com.sun.hotspot.c1x; | |
22 | |
23 import java.util.*; | |
24 | |
25 import com.sun.cri.ci.*; | |
26 import com.sun.cri.ri.*; | |
27 | |
28 /** | |
29 * Represents a method signature. | |
30 * | |
31 * @author Thomas Wuerthinger, Lukas Stadler | |
32 */ | |
33 public class HotSpotSignature extends CompilerObject implements RiSignature { | |
34 | |
35 private final List<String> arguments = new ArrayList<String>(); | |
36 private final String returnType; | |
37 private final String originalString; | |
38 private RiType[] argumentTypes; | |
39 private RiType returnTypeCache; | |
40 | |
41 public HotSpotSignature(Compiler compiler, String signature) { | |
42 super(compiler); | |
43 assert signature.length() > 0; | |
44 this.originalString = signature; | |
45 | |
46 if (signature.charAt(0) == '(') { | |
47 int cur = 1; | |
48 while (cur < signature.length() && signature.charAt(cur) != ')') { | |
49 int nextCur = parseSignature(signature, cur); | |
50 arguments.add(signature.substring(cur, nextCur)); | |
51 cur = nextCur; | |
52 } | |
53 | |
54 cur++; | |
55 int nextCur = parseSignature(signature, cur); | |
56 returnType = signature.substring(cur, nextCur); | |
57 assert nextCur == signature.length(); | |
58 } else { | |
59 returnType = null; | |
60 } | |
61 } | |
62 | |
63 private int parseSignature(String signature, int cur) { | |
64 char first; | |
65 do { | |
66 first = signature.charAt(cur++); | |
67 } while (first == '['); | |
68 | |
69 switch (first) { | |
70 case 'L': | |
71 while (signature.charAt(cur) != ';') { | |
72 cur++; | |
73 } | |
74 cur++; | |
75 break; | |
76 case 'V': | |
77 case 'I': | |
78 case 'B': | |
79 case 'C': | |
80 case 'D': | |
81 case 'F': | |
82 case 'J': | |
83 case 'S': | |
84 case 'Z': | |
85 break; | |
86 default: | |
87 assert false; | |
88 } | |
89 return cur; | |
90 } | |
91 | |
92 @Override | |
93 public int argumentCount(boolean withReceiver) { | |
94 return arguments.size() + (withReceiver ? 1 : 0); | |
95 } | |
96 | |
97 @Override | |
98 public CiKind argumentKindAt(int index) { | |
99 return CiKind.fromTypeString(arguments.get(index)); | |
100 } | |
101 | |
102 @Override | |
103 public int argumentSlots(boolean withReceiver) { | |
104 | |
105 int argSlots = 0; | |
106 for (int i = 0; i < argumentCount(false); i++) { | |
107 argSlots += argumentKindAt(i).sizeInSlots(); | |
108 } | |
109 | |
110 return argSlots + (withReceiver ? 1 : 0); | |
111 } | |
112 | |
113 @Override | |
114 public RiType argumentTypeAt(int index, RiType accessingClass) { | |
115 if (argumentTypes == null) { | |
116 argumentTypes = new RiType[arguments.size()]; | |
117 } | |
118 RiType type = argumentTypes[index]; | |
119 if (type == null) { | |
120 type = compiler.getVMEntries().RiSignature_lookupType(arguments.get(index), (HotSpotTypeResolved) accessingClass); | |
121 argumentTypes[index] = type; | |
122 } | |
123 return type; | |
124 } | |
125 | |
126 @Override | |
127 public String asString() { | |
128 return originalString; | |
129 } | |
130 | |
131 @Override | |
132 public CiKind returnKind() { | |
133 return CiKind.fromTypeString(returnType); | |
134 } | |
135 | |
136 @Override | |
137 public RiType returnType(RiType accessingClass) { | |
138 if (returnTypeCache == null) { | |
139 returnTypeCache = compiler.getVMEntries().RiSignature_lookupType(returnType, (HotSpotTypeResolved) accessingClass); | |
140 } | |
141 return returnTypeCache; | |
142 } | |
143 | |
144 @Override | |
145 public String toString() { | |
146 return "HotSpotSignature<" + originalString + ">"; | |
147 } | |
148 | |
149 } |