/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/**
* Convert code into HTML file.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*
*/
private static boolean wide=false;
{
this.class_name = class_name;
this.constant_pool = constant_pool;
this.constant_html = constant_html;
writeMethod(methods[i], i);
}
/**
* Disassemble a stream of byte codes and return the
* string representation.
*
* @param stream data input stream
* @return String representation of byte code
*/
throws IOException
{
int[] jump_table;
/* Special case: Skip (0-3) padding bytes, i.e., the
* following bytes are 4-byte-aligned
*/
for(int i=0; i < no_pad_bytes; i++)
// Both cases have a field default_offset in common
}
switch(opcode) {
case TABLESWITCH:
default_offset += offset;
// Print switch indices in first row (and default)
}
// Print target and default indices in second row
break;
/* Lookup switch has variable length arguments.
*/
case LOOKUPSWITCH:
jump_table = new int[npairs];
default_offset += offset;
// Print switch indices in first row (and default)
for(int i=0; i < npairs; i++) {
}
// Print target and default indices in second row
for(int i=0; i < npairs; i++)
break;
/* Two address bytes + offset from start of byte stream form the
* jump target.
*/
break;
/* Same for 32-bit wide jumps
*/
windex + "</A>");
break;
/* Index byte references local variable (register)
*/
case RET:
if(wide) {
wide=false; // Clear flag
}
else
break;
/*
* Remember wide byte which is used to form a 16-bit address in the
* following instruction. Relies on that the method is called again with
* the following opcode.
*/
case WIDE:
wide = true;
break;
/* Array of basic type.
*/
case NEWARRAY:
break;
*/
}
else
break;
/* Operands are references to classes in constant pool
*/
break;
/* Operands are references to methods in constant pool
*/
ConstantInterfaceMethodref c=(ConstantInterfaceMethodref)constant_pool.getConstant(m_index, CONSTANT_InterfaceMethodref);
class_index = c.getClassIndex();
index = c.getNameAndTypeIndex();
}
else {
class_index = c.getClassIndex();
index = c.getNameAndTypeIndex();
}
str = Class2HTML.toHTML(constant_pool.constantToString(constant_pool.getConstant(index, CONSTANT_NameAndType)));
// Get signature, i.e., types
// List arguments
}
// Attach return type
break;
/* Operands are references to items in constant pool
*/
"\" TARGET=\"ConstantPool\">" +
"</a>");
break;
case LDC:
"\" TARGET=\"ConstantPool\">" +
"</a>");
break;
/* Array of references.
*/
case ANEWARRAY:
break;
/* Multidimensional array of references.
*/
case MULTIANEWARRAY:
break;
/* Increment local variable.
*/
case IINC:
if(wide) {
wide = false;
}
else {
}
break;
default:
switch(TYPE_OF_OPERANDS[opcode][i]) {
case T_BYTE:
break;
case T_SHORT: // Either branch or index
break;
case T_INT:
break;
default: // Never reached
}
}
}
}
}
/**
* Find all target addresses in code, so that they can be marked
* with <A NAME = ...>. Target addresses are kept in an BitSet object.
*/
throws IOException
{
int index;
int opcode;
/* First get Code attribute from method and the exceptions handled
* (try .. catch) in this method. We only need the line number here.
*/
for(int i=0; i < len; i++) {
}
// Look for local variables and their range
}
break;
}
}
}
// Get target addresses from GOTO, JSR, TABLESWITCH, etc.
//System.out.println(OPCODE_NAMES[opcode]);
switch(opcode) {
case TABLESWITCH: case LOOKUPSWITCH:
//bytes.readByte(); // Skip already read byte
int default_offset, offset;
for(int j=0; j < no_pad_bytes; j++)
// Both cases have a field default_offset in common
if(opcode == TABLESWITCH) {
default_offset += offset;
}
}
else { // LOOKUPSWITCH
default_offset += offset;
for(int j=0; j < npairs; j++) {
}
}
break;
//bytes.readByte(); // Skip already read byte
break;
//bytes.readByte(); // Skip already read byte
break;
default:
bytes.unreadByte();
}
}
}
/**
* Write a single method with the byte code associated with it.
*/
throws IOException
{
// Get raw signature
// Get array of strings containing the argument types
// Get return type string
// Get method name
// Get method's access flags
// Get the method's attributes, the Code Attribute in particular
}
if(tag != ATTR_UNKNOWN)
else
c = (Code)attributes[i];
}
}
}
}
//System.out.println(name + "\n" + Utility.codeToString(code, constant_pool, 0, -1));
// Print the byte code
"<TH ALIGN=LEFT>Instruction</TH><TH ALIGN=LEFT>Argument</TH>");
/* Set an anchor mark if this line is targetted by a goto, jsr, etc.
* Defining an anchor for every line is very inefficient!
*/
else
}
// Mark last line, may be targetted from Attributes window
}
}
}