Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

BasicBlock.java

00001 package ca.mcgill.sable.soot.coffi;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Jimple, a 3-address code Java(TM) bytecode representation.        *
00005  * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca)    *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project of the Sable Research Group,      *
00009  * School of Computer Science, McGill University, Canada             *
00010  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00011  * modification not identified as such is not covered by the         *
00012  * preceding statement.                                              *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this library; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other Sable Research Group projects, please      *
00033  * visit the web site: http://www.sable.mcgill.ca/                   *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 
00036 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00037  * Coffi, a bytecode parser for the Java(TM) language.               *
00038  * Copyright (C) 1996, 1997 Clark Verbrugge (clump@sable.mcgill.ca). *
00039  * All rights reserved.                                              *
00040  *                                                                   *
00041  * This work was done as a project of the Sable Research Group,      *
00042  * School of Computer Science, McGill University, Canada             *
00043  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00044  * modification not identified as such is not covered by the         *
00045  * preceding statement.                                              *
00046  *                                                                   *
00047  * This work is free software; you can redistribute it and/or        *
00048  * modify it under the terms of the GNU Library General Public       *
00049  * License as published by the Free Software Foundation; either      *
00050  * version 2 of the License, or (at your option) any later version.  *
00051  *                                                                   *
00052  * This work is distributed in the hope that it will be useful,      *
00053  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00054  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00055  * Library General Public License for more details.                  *
00056  *                                                                   *
00057  * You should have received a copy of the GNU Library General Public *
00058  * License along with this library; if not, write to the             *
00059  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00060  * Boston, MA  02111-1307, USA.                                      *
00061  *                                                                   *
00062  * Java is a trademark of Sun Microsystems, Inc.                     *
00063  *                                                                   *
00064  * To submit a bug report, send a comment, or get the latest news on *
00065  * this project and other Sable Research Group projects, please      *
00066  * visit the web site: http://www.sable.mcgill.ca/                   *
00067  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00068 
00069 /*
00070  Reference Version
00071  -----------------
00072  This is the latest official version on which this file is based.
00073  The reference version is: $CoffiVersion: 1.1 $
00074                            $SootVersion: 1.beta.4 $
00075 
00076  Change History
00077  --------------
00078  A) Notes:
00079 
00080  Please use the following template.  Most recent changes should
00081  appear at the top of the list.
00082 
00083  - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate]
00084    [description of modification].
00085 
00086  Any Modification flagged with "(*)" was done as a project of the
00087  Sable Research Group, School of Computer Science,
00088  McGill University, Canada (http://www.sable.mcgill.ca/).
00089 
00090  You should add your copyright, using the following template, at
00091  the top of this file, along with other copyrights.
00092 
00093  *                                                                   *
00094  * Modifications by [name] are                                       *
00095  * Copyright (C) [year(s)] [your name (or company)].  All rights     *
00096  * reserved.                                                         *
00097  *                                                                   *
00098 
00099  B) Changes:
00100 
00101  - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00102    Repackaged all source files and performed extensive modifications.
00103    First initial release of Soot.
00104 
00105  - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00106    First internal release (Version 0.1).
00107 */
00108 
00109 import java.util.Enumeration;
00110 import java.util.Vector;
00111 
00112 /** Represents one basic block in a control flow graph.
00113  * @see CFG
00114  * @see ClassFile#parse
00115  * @author Clark Verbrugge
00116  */
00117 class BasicBlock {
00118    /** Number of instructions in this block. */
00119    public int size;
00120    /** Head of the list of instructions. */
00121    public Instruction head;
00122    /** Tail of the list of instructions.
00123     * <p>
00124     * Normally, the last instruction will have a next pointer with value
00125     * <i>null</i>.  After a Instruction sequences are reconstructed though,
00126     * the instruction lists
00127     * are rejoined in order, and so the tail instruction will not
00128     * have a <i>null</i> next pointer.
00129     * @see CFG#reconstructInstructions
00130     */
00131    public Instruction tail;
00132    /** Vector of predecessor BasicBlocks.
00133     * @see java.util.Vector
00134     */
00135    public Vector succ;
00136    /** Vector of successor BasicBlocks.
00137     * @see java.util.Vector
00138     */
00139    public Vector pred;
00140 
00141    public boolean inq;
00142    /** Flag for whether starting an exception or not. */
00143    public boolean beginException;
00144    /** Flag for whether starting main code block or not. */
00145    public boolean beginCode;
00146    /** Flag for semantic stack analysis fixup pass.
00147     * @see CFG#jimplify
00148     */
00149 
00150    boolean done;
00151 
00152    /** Next BasicBlock in the CFG, in the parse order. */
00153    public BasicBlock next;
00154    /** Unique (among basic blocks) id. */
00155    public long id;                   // unique id
00156 
00157    private short wide;                 // convert indices when parsing jimple
00158 
00159    private static long ids;           // for generating unique ids
00160 
00161    /** Constructs a BasicBlock consisting of the given list of Instructions.
00162     * @param insts list of instructions composing this basic block.
00163     */
00164 
00165    private ca.mcgill.sable.soot.jimple.Stmt stmt;  // statement generated
00166 
00167    ca.mcgill.sable.util.List statements;
00168    ca.mcgill.sable.util.Set addressesToFixup = new ca.mcgill.sable.util.VectorSet();
00169 
00170    public BasicBlock(Instruction insts) {
00171       id = ids++;
00172       head = insts;
00173       tail = head;
00174       size = 0;
00175       if (head!=null) {
00176          size++;
00177          while (tail.next!=null) {
00178             size++;
00179             tail = tail.next;
00180          }
00181       }
00182       succ = new Vector(2,10);
00183       pred = new Vector(2,3);
00184    }   
00185    /** True if this block represents the same piece of code.  Basically
00186     * compares labels of the head instructions.
00187     * @param b block to compare against.
00188     * @return <i>true</i> if they do, <i>false</i> if they don't.
00189     */
00190    public boolean equals(BasicBlock b) {
00191       if (b.head.label == head.label) return true;
00192       return false;
00193    }   
00194    ca.mcgill.sable.soot.jimple.Stmt getHeadJStmt()
00195    {
00196       return (ca.mcgill.sable.soot.jimple.Stmt) statements.get(0);
00197    }   
00198    ca.mcgill.sable.soot.jimple.Stmt getTailJStmt()
00199    {
00200       return (ca.mcgill.sable.soot.jimple.Stmt) statements.get(statements.size() - 1);
00201    }   
00202    /** Computes a hash code for this block from the label of the
00203     * first instruction in its contents.
00204     * @return the hash code.
00205     * @see Instruction#label
00206     */
00207    public int hashCode() {
00208       return (new Integer(head.label)).hashCode();
00209    }   
00210    /** For printing the string "BB: " + id.
00211     */
00212    public String toString() { return "BB: " + id; }   
00213    // Returns the index of b given the current wide
00214    // wide to 0
00215    private int wideIndex(short b) {
00216       int i = ((((int)wide)<<8)&0xff00) | (((int)b)&0xff);
00217       wide = (byte)0;
00218       return i;
00219    }   
00220 }

Generated at Thu Feb 7 06:40:33 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001