# HG changeset patch # User Paul Boddie # Date 1106512346 -3600 # Node ID 3270cc49c46f8e961acc8797a977845190c80098 # Parent c0aa5f64dd9aad761fce9760e0b9882459b60952 Added a get_bytecode method to the bytecode writer which provides a list of byte values (including finalised "lazy" values). Added missing instruction support to the disassembler program class. Added a hack to avoid issues with apparently strange exception tables. diff -r c0aa5f64dd9a -r 3270cc49c46f javaclass/bytecode.py --- a/javaclass/bytecode.py Sun Jan 23 01:59:37 2005 +0100 +++ b/javaclass/bytecode.py Sun Jan 23 21:32:26 2005 +0100 @@ -8,11 +8,10 @@ """ import classfile -from dis import cmp_op # for access to Python bytecode values and operators +from dis import cmp_op, opname # for access to Python bytecode values and operators try: from dis import opmap except ImportError: - from dis import opname opmap = {} for i in range(0, len(opname)): opmap[opname[i]] = i @@ -70,9 +69,9 @@ # A list of external names. self.external_names = [] - def get_output(self): - - "Return the output of the writer as a string." + def get_bytecodes(self): + + "Return the list of bytecodes written to the writer." output = [] for element in self.output: @@ -80,6 +79,15 @@ value = element.value else: value = element + output.append(value) + return output + + def get_output(self): + + "Return the output of the writer as a string." + + output = [] + for value in self.get_bytecodes(): # NOTE: ValueError gets raised for bad values here. output.append(chr(value)) return "".join(output) @@ -730,6 +738,12 @@ for exception in reversed_exception_table: + # NOTE: Strange case with javac from JDK 1.4 but not JDK 1.3: + # NOTE: start_pc == handler_pc + + if exception.start_pc == exception.handler_pc: + continue + # Index start positions. if not exception_block_start.has_key(exception.start_pc): @@ -1079,6 +1093,10 @@ print "(start_handler %s)" % exc_name def pop_block(self): print "(pop_block)" + def load_const(self, const): + print "(load_const %s)" % const + def return_value(self): + print "(return_value)" class BytecodeTranslator(BytecodeReader): @@ -1958,6 +1976,7 @@ def disassemble(class_file, method): disassembler = BytecodeDisassembler(class_file) disassembler.process(method, BytecodeDisassemblerProgram()) + return disassembler class ClassTranslator: