Mercurial > hg > graal-compiler
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotSignature.java @ 1416:1b41af477605
Added HotSpotVM project Java source files.
author | Thomas Wuerthinger <thomas.wuerthinger@gmail.com> |
---|---|
date | Wed, 23 Jun 2010 16:36:58 +0200 |
parents | |
children | 44efca8a02d6 |
comparison
equal
deleted
inserted
replaced
1415:712c7ff1afc1 | 1416:1b41af477605 |
---|---|
1 package com.sun.hotspot.c1x; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import com.sun.cri.ci.CiKind; | |
7 import com.sun.cri.ri.RiSignature; | |
8 import com.sun.cri.ri.RiType; | |
9 | |
10 public class HotSpotSignature implements RiSignature { | |
11 | |
12 private final List<String> arguments = new ArrayList<String>(); | |
13 private final String returnType; | |
14 private final String originalString; | |
15 | |
16 public HotSpotSignature(String signature) { | |
17 | |
18 assert signature.length() > 0; | |
19 this.originalString = signature; | |
20 | |
21 if (signature.charAt(0) == '(') { | |
22 int cur = 1; | |
23 while (cur < signature.length() && signature.charAt(cur) != ')') { | |
24 int nextCur = parseSignature(signature, cur); | |
25 arguments.add(signature.substring(cur, nextCur)); | |
26 cur = nextCur; | |
27 } | |
28 | |
29 cur++; | |
30 int nextCur = parseSignature(signature, cur); | |
31 returnType = signature.substring(cur, nextCur); | |
32 assert nextCur == signature.length(); | |
33 } else { | |
34 returnType = null; | |
35 } | |
36 } | |
37 | |
38 private int parseSignature(String signature, int cur) { | |
39 | |
40 char first = signature.charAt(cur); | |
41 switch (first) { | |
42 | |
43 case '[': | |
44 return parseSignature(signature, cur + 1); | |
45 | |
46 case 'L': | |
47 while (signature.charAt(cur) != ';') | |
48 cur++; | |
49 cur++; | |
50 break; | |
51 | |
52 case 'V': | |
53 case 'I': | |
54 case 'B': | |
55 case 'C': | |
56 case 'D': | |
57 case 'F': | |
58 case 'J': | |
59 case 'S': | |
60 case 'Z': | |
61 cur++; | |
62 break; | |
63 | |
64 default: | |
65 assert false; | |
66 | |
67 } | |
68 | |
69 return cur; | |
70 } | |
71 | |
72 @Override | |
73 public int argumentCount(boolean withReceiver) { | |
74 return arguments.size() + (withReceiver ? 1 : 0); | |
75 } | |
76 | |
77 @Override | |
78 public CiKind argumentKindAt(int index) { | |
79 CiKind kind = CiKind.fromTypeString(arguments.get(index)); | |
80 System.out.println("argument kind: " + index + " is " + kind); | |
81 return kind; | |
82 } | |
83 | |
84 @Override | |
85 public int argumentSlots(boolean withReceiver) { | |
86 | |
87 int argSlots = 0; | |
88 for (int i = 0; i < argumentCount(false); i++) { | |
89 argSlots += argumentKindAt(i).sizeInSlots(); | |
90 } | |
91 | |
92 return argSlots + (withReceiver ? 1 : 0); | |
93 } | |
94 | |
95 @Override | |
96 public RiType argumentTypeAt(int index, RiType accessingClass) { | |
97 System.out.println("argument type at " + index); | |
98 Object accessor = null; | |
99 if (accessingClass instanceof HotSpotType) { | |
100 accessor = ((HotSpotType)accessingClass).klassOop; | |
101 } | |
102 return VMEntries.RiSignature_lookupType(arguments.get(index), accessor); | |
103 } | |
104 | |
105 @Override | |
106 public String asString() { | |
107 return originalString; | |
108 } | |
109 | |
110 @Override | |
111 public CiKind returnKind() { | |
112 return CiKind.fromTypeString(returnType); | |
113 } | |
114 | |
115 @Override | |
116 public RiType returnType(RiType accessingClass) { | |
117 return VMEntries.RiSignature_lookupType(returnType, accessingClass); | |
118 } | |
119 | |
120 } |