comparison graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java @ 2616:3558ca7088c0

FrameState and Graphviz changes: * removed popx, pushx methods from GraphBuilder * FrameState subclass of Value * added String shortName() to Node * added GraphvizPrinter option to use short names * small hack in GraphvizPrinter: omit FrameState->Local connections * added GraalGraphviz to implicit classpatch (read from GRAAL env var)
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 09 May 2011 17:00:25 +0200
parents bd235cb4375a
children 8c02ca1e9eb1
comparison
equal deleted inserted replaced
2615:5768534fd4e5 2616:3558ca7088c0
32 32
33 import static com.sun.c1x.value.ValueUtil.*; 33 import static com.sun.c1x.value.ValueUtil.*;
34 import static java.lang.reflect.Modifier.*; 34 import static java.lang.reflect.Modifier.*;
35 35
36 36
37 public class FrameStateBuilder { 37 public class FrameStateBuilder implements FrameStateAccess {
38 38
39 private final Graph graph; 39 private final Graph graph;
40 40
41 private final Value[] locals; 41 private final Value[] locals;
42 private final Value[] stack; 42 private final Value[] stack;
73 } 73 }
74 this.locks = new ArrayList<Value>(); 74 this.locks = new ArrayList<Value>();
75 } 75 }
76 76
77 public void initializeFrom(FrameState other) { 77 public void initializeFrom(FrameState other) {
78 assert locals.length == other.localsSize; 78 assert locals.length == other.localsSize();
79 assert stack.length >= other.stackSize(); 79 assert stack.length >= other.stackSize();
80 80
81 this.stackIndex = other.stackSize(); 81 this.stackIndex = other.stackSize();
82 System.arraycopy(other.values, 0, locals, 0, locals.length); 82 for (int i = 0; i < other.localsSize(); i++) {
83 System.arraycopy(other.values, other.localsSize(), stack, 0, stackIndex); 83 locals[i] = other.localAt(i);
84 }
85 for (int i = 0; i < other.stackSize(); i++) {
86 stack[i] = other.stackAt(i);
87 }
84 locks.clear(); 88 locks.clear();
85 for (int i = 0; i < other.locksSize(); i++) { 89 for (int i = 0; i < other.locksSize(); i++) {
86 locks.add(other.lockAt(i)); 90 locks.add(other.lockAt(i));
87 } 91 }
88 } 92 }
89 93
90 public FrameState create(int bci) { 94 public FrameState create(int bci) {
91 return new FrameState(bci, locals, stack, stackIndex, locks); 95 return new FrameState(bci, locals, stack, stackIndex, locks, graph);
92 } 96 }
93 97
94 /** 98 /**
95 * Pushes an instruction onto the stack with the expected type. 99 * Pushes an instruction onto the stack with the expected type.
96 * @param kind the type expected for this instruction 100 * @param kind the type expected for this instruction
167 * @param x the instruction to push onto the stack 171 * @param x the instruction to push onto the stack
168 */ 172 */
169 public void dpush(Value x) { 173 public void dpush(Value x) {
170 xpush(assertDouble(x)); 174 xpush(assertDouble(x));
171 xpush(null); 175 xpush(null);
176 }
177
178 public void pushReturn(CiKind kind, Value x) {
179 if (kind != CiKind.Void) {
180 push(kind.stackKind(), x);
181 }
172 } 182 }
173 183
174 /** 184 /**
175 * Pops an instruction off the stack with the expected type. 185 * Pops an instruction off the stack with the expected type.
176 * @param kind the expected type 186 * @param kind the expected type
261 assert stack[base + i] != null || stack[base + i - 1].kind.jvmSlots == 2; 271 assert stack[base + i] != null || stack[base + i - 1].kind.jvmSlots == 2;
262 r[i] = stack[base + i]; 272 r[i] = stack[base + i];
263 } 273 }
264 stackIndex = base; 274 stackIndex = base;
265 return r; 275 return r;
276 }
277
278 public CiKind peekKind() {
279 Value top = stackAt(stackSize() - 1);
280 if (top == null) {
281 top = stackAt(stackSize() - 2);
282 assert top != null;
283 assert top.kind.isDoubleWord();
284 }
285 return top.kind;
266 } 286 }
267 287
268 /** 288 /**
269 * Truncates this stack to the specified size. 289 * Truncates this stack to the specified size.
270 * @param size the size to truncate to 290 * @param size the size to truncate to
432 throw new UnsupportedOperationException("cannot remove from array"); 452 throw new UnsupportedOperationException("cannot remove from array");
433 } 453 }
434 454
435 } 455 }
436 456
457
458 @Override
459 public FrameState duplicate() {
460 return create(-1);
461 }
462
463 @Override
464 public Value valueAt(int i) {
465 if (i < locals.length) {
466 return locals[i];
467 } else if (i < locals.length + stackIndex) {
468 return stack[i - locals.length];
469 } else {
470 return locks.get(i - locals.length - stack.length);
471 }
472 }
473
437 } 474 }