1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
\r
3 * The contents of this file are subject to the Netscape Public
\r
4 * License Version 1.1 (the "License"); you may not use this file
\r
5 * except in compliance with the License. You may obtain a copy of
\r
6 * the License at http://www.mozilla.org/NPL/
\r
8 * Software distributed under the License is distributed on an "AS
\r
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
\r
10 * implied. See the License for the specific language governing
\r
11 * rights and limitations under the License.
\r
13 * The Original Code is Rhino code, released
\r
16 * The Initial Developer of the Original Code is Netscape
\r
17 * Communications Corporation. Portions created by Netscape are
\r
18 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
\r
24 * Alternatively, the contents of this file may be used under the
\r
25 * terms of the GNU Public License (the "GPL"), in which case the
\r
26 * provisions of the GPL are applicable instead of those above.
\r
27 * If you wish to allow use of your version of this file only
\r
28 * under the terms of the GPL and not to allow others to use your
\r
29 * version of this file under the NPL, indicate your decision by
\r
30 * deleting the provisions above and replace them with the notice
\r
31 * and other provisions required by the GPL. If you do not delete
\r
32 * the provisions above, a recipient may use your version of this
\r
33 * file under either the NPL or the GPL.
\r
36 package org.mozilla.javascript;
\r
38 public class Label {
\r
40 private static final int FIXUPTABLE_SIZE = 8;
\r
42 private static final boolean DEBUG = true;
\r
49 public short getPC()
\r
54 public void fixGotos(byte theCodeBuffer[])
\r
57 if ((itsPC == -1) && (itsFixupTable != null))
\r
58 throw new RuntimeException("Unlocated label");
\r
60 if (itsFixupTable != null) {
\r
61 for (int i = 0; i < itsFixupTableTop; i++) {
\r
62 int fixupSite = itsFixupTable[i];
\r
63 // -1 to get delta from instruction start
\r
64 short offset = (short)(itsPC - (fixupSite - 1));
\r
65 theCodeBuffer[fixupSite++] = (byte)(offset >> 8);
\r
66 theCodeBuffer[fixupSite] = (byte)offset;
\r
69 itsFixupTable = null;
\r
72 public void setPC(short thePC)
\r
75 if ((itsPC != -1) && (itsPC != thePC)) {
\r
76 throw new RuntimeException("Duplicate label");
\r
83 public void addFixup(int fixupSite)
\r
85 if (itsFixupTable == null) {
\r
86 itsFixupTableTop = 1;
\r
87 itsFixupTable = new int[FIXUPTABLE_SIZE];
\r
88 itsFixupTable[0] = fixupSite;
\r
91 if (itsFixupTableTop == itsFixupTable.length) {
\r
92 int oldLength = itsFixupTable.length;
\r
93 int newTable[] = new int[oldLength + FIXUPTABLE_SIZE];
\r
94 System.arraycopy(itsFixupTable, 0, newTable, 0, oldLength);
\r
95 itsFixupTable = newTable;
\r
97 itsFixupTable[itsFixupTableTop++] = fixupSite;
\r
101 private short itsPC = -1;
\r
102 private int itsFixupTable[];
\r
103 private int itsFixupTableTop;
\r