001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1/GPL 2.0
003: *
004: * The contents of this file are subject to the Mozilla Public License Version
005: * 1.1 (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS" basis,
010: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: * for the specific language governing rights and limitations under the
012: * License.
013: *
014: * The Original Code is Rhino code, released
015: * May 6, 1999.
016: *
017: * The Initial Developer of the Original Code is
018: * Netscape Communications Corporation.
019: * Portions created by the Initial Developer are Copyright (C) 1997-1999
020: * the Initial Developer. All Rights Reserved.
021: *
022: * Contributor(s):
023: * Norris Boyd
024: * Roger Lawrence
025: *
026: * Alternatively, the contents of this file may be used under the terms of
027: * the GNU General Public License Version 2 or later (the "GPL"), in which
028: * case the provisions of the GPL are applicable instead of those above. If
029: * you wish to allow use of your version of this file only under the terms of
030: * the GPL and not to allow others to use your version of this file under the
031: * MPL, indicate your decision by deleting the provisions above and replacing
032: * them with the notice and other provisions required by the GPL. If you do
033: * not delete the provisions above, a recipient may use your version of this
034: * file under either the MPL or the GPL.
035: *
036: * ***** END LICENSE BLOCK ***** */
037:
038: package org.mozilla.javascript.optimizer;
039:
040: class DataFlowBitSet {
041:
042: private int itsBits[];
043: private int itsSize;
044:
045: DataFlowBitSet(int size) {
046: itsSize = size;
047: itsBits = new int[(size + 31) >> 5];
048: }
049:
050: void set(int n) {
051: if (!(0 <= n && n < itsSize))
052: badIndex(n);
053: itsBits[n >> 5] |= 1 << (n & 31);
054: }
055:
056: boolean test(int n) {
057: if (!(0 <= n && n < itsSize))
058: badIndex(n);
059: return ((itsBits[n >> 5] & (1 << (n & 31))) != 0);
060: }
061:
062: void not() {
063: int bitsLength = itsBits.length;
064: for (int i = 0; i < bitsLength; i++)
065: itsBits[i] = ~itsBits[i];
066: }
067:
068: void clear(int n) {
069: if (!(0 <= n && n < itsSize))
070: badIndex(n);
071: itsBits[n >> 5] &= ~(1 << (n & 31));
072: }
073:
074: void clear() {
075: int bitsLength = itsBits.length;
076: for (int i = 0; i < bitsLength; i++)
077: itsBits[i] = 0;
078: }
079:
080: void or(DataFlowBitSet b) {
081: int bitsLength = itsBits.length;
082: for (int i = 0; i < bitsLength; i++)
083: itsBits[i] |= b.itsBits[i];
084: }
085:
086: public String toString() {
087: StringBuffer sb = new StringBuffer();
088: sb.append("DataFlowBitSet, size = ");
089: sb.append(itsSize);
090: sb.append('\n');
091: int bitsLength = itsBits.length;
092: for (int i = 0; i < bitsLength; i++) {
093: sb.append(Integer.toHexString(itsBits[i]));
094: sb.append(' ');
095: }
096: return sb.toString();
097: }
098:
099: boolean df(DataFlowBitSet in, DataFlowBitSet gen,
100: DataFlowBitSet notKill) {
101: int bitsLength = itsBits.length;
102: boolean changed = false;
103: for (int i = 0; i < bitsLength; i++) {
104: int oldBits = itsBits[i];
105: itsBits[i] = (in.itsBits[i] | gen.itsBits[i])
106: & notKill.itsBits[i];
107: changed |= (oldBits != itsBits[i]);
108: }
109: return changed;
110: }
111:
112: boolean df2(DataFlowBitSet in, DataFlowBitSet gen,
113: DataFlowBitSet notKill) {
114: int bitsLength = itsBits.length;
115: boolean changed = false;
116: for (int i = 0; i < bitsLength; i++) {
117: int oldBits = itsBits[i];
118: itsBits[i] = (in.itsBits[i] & notKill.itsBits[i])
119: | gen.itsBits[i];
120: changed |= (oldBits != itsBits[i]);
121: }
122: return changed;
123: }
124:
125: private void badIndex(int n) {
126: throw new RuntimeException("DataFlowBitSet bad index " + n);
127: }
128: }
|