Mercurial > hg > graal-jvmci-8
comparison graal/Compiler/src/com/sun/c1x/asm/Label.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, 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 com.sun.c1x.asm; | |
24 | |
25 import com.sun.c1x.util.*; | |
26 | |
27 /** | |
28 * This class represents a label within assembly code. | |
29 * | |
30 * @author Marcelo Cintra | |
31 */ | |
32 public final class Label { | |
33 | |
34 private int position = -1; | |
35 | |
36 /** | |
37 * References to instructions that jump to this unresolved label. | |
38 * These instructions need to be patched when the label is bound | |
39 * using the {@link #patchInstructions(AbstractAssembler)} method. | |
40 */ | |
41 private IntList patchPositions = new IntList(4); | |
42 | |
43 /** | |
44 * Returns the position of this label in the code buffer. | |
45 * @return the position | |
46 */ | |
47 public int position() { | |
48 assert position >= 0 : "Unbound label is being referenced"; | |
49 return position; | |
50 } | |
51 | |
52 public Label() { | |
53 } | |
54 | |
55 public Label(int position) { | |
56 bind(position); | |
57 } | |
58 | |
59 /** | |
60 * Binds the label to the specified position. | |
61 * @param pos the position | |
62 */ | |
63 public void bind(int pos) { | |
64 this.position = pos; | |
65 assert isBound(); | |
66 } | |
67 | |
68 public boolean isBound() { | |
69 return position >= 0; | |
70 } | |
71 | |
72 public void addPatchAt(int branchLocation) { | |
73 assert !isBound() : "Label is already bound"; | |
74 patchPositions.add(branchLocation); | |
75 } | |
76 | |
77 public void patchInstructions(AbstractAssembler masm) { | |
78 assert isBound() : "Label should be bound"; | |
79 int target = position; | |
80 for (int i = 0; i < patchPositions.size(); ++i) { | |
81 int pos = patchPositions.get(i); | |
82 masm.patchJumpTarget(pos, target); | |
83 } | |
84 } | |
85 | |
86 @Override | |
87 public String toString() { | |
88 return "label"; | |
89 } | |
90 } |