use member functions to access Instruction fields

cleaned up imports
use appendBlock instead of sequentialT1


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1072 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 26 years ago
parent 8d4691f8b0
commit d4b15f7b44
  1. 80
      jode/jode/decompiler/MethodAnalyzer.java

@ -21,7 +21,12 @@ package jode.decompiler;
import jode.AssertError; import jode.AssertError;
import jode.Decompiler; import jode.Decompiler;
import jode.GlobalOptions; import jode.GlobalOptions;
import jode.bytecode.*; import jode.bytecode.BytecodeInfo;
import jode.bytecode.ClassInfo;
import jode.bytecode.MethodInfo;
import jode.bytecode.Handler;
import jode.bytecode.Instruction;
import jode.bytecode.LocalVariableInfo;
import jode.jvm.SyntheticAnalyzer; import jode.jvm.SyntheticAnalyzer;
import jode.type.*; import jode.type.*;
import jode.expr.Expression; import jode.expr.Expression;
@ -179,6 +184,8 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
} }
public void insertStructuredBlock(StructuredBlock superBlock) { public void insertStructuredBlock(StructuredBlock superBlock) {
if (methodHeader != null)
throw new IllegalStateException();
if (insertBlock != null) if (insertBlock != null)
throw new jode.AssertError(); throw new jode.AssertError();
insertBlock = superBlock; insertBlock = superBlock;
@ -239,30 +246,26 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
* predecessor other than the previous instruction. * predecessor other than the previous instruction.
*/ */
for (Instruction instr = code.getFirstInstr(); for (Instruction instr = code.getFirstInstr();
instr != null; instr = instr.nextByAddr) { instr != null; instr = instr.getNextByAddr()) {
if (instr.prevByAddr == null if (instr.getPrevByAddr() == null
|| instr.prevByAddr.alwaysJumps || instr.getPrevByAddr().doesAlwaysJump()
|| instr.preds != null) || instr.getPreds() != null)
instr.tmpInfo = new FlowBlock instr.setTmpInfo(new FlowBlock(this, instr.getAddr()));
(this, instr.addr, instr.length);
} }
for (int i=0; i < handlers.length; i++) { for (int i=0; i < handlers.length; i++) {
Instruction instr = handlers[i].start; Instruction instr = handlers[i].start;
if (instr.tmpInfo == null) if (instr.getTmpInfo() == null)
instr.tmpInfo instr.setTmpInfo(new FlowBlock(this, instr.getAddr()));
= new FlowBlock(this, instr.addr, instr.length);
/* end doesn't have a predecessor, but we must prevent /* end doesn't have a predecessor, but we must prevent
* it from being merged with the previous instructions. * it from being merged with the previous instructions.
*/ */
instr = handlers[i].end.nextByAddr; instr = handlers[i].end.getNextByAddr();
if (instr.tmpInfo == null) if (instr.getTmpInfo() == null)
instr.tmpInfo instr.setTmpInfo(new FlowBlock(this, instr.getAddr()));
= new FlowBlock(this, instr.addr, instr.length);
instr = handlers[i].catcher; instr = handlers[i].catcher;
if (instr.tmpInfo == null) if (instr.getTmpInfo() == null)
instr.tmpInfo instr.setTmpInfo(new FlowBlock(this, instr.getAddr()));
= new FlowBlock(this, instr.addr, instr.length);
} }
/* While we read the opcodes into FlowBlocks /* While we read the opcodes into FlowBlocks
@ -274,57 +277,58 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
FlowBlock lastBlock = null; FlowBlock lastBlock = null;
boolean lastSequential = false; boolean lastSequential = false;
for (Instruction instr = code.getFirstInstr(); for (Instruction instr = code.getFirstInstr();
instr != null; instr = instr.nextByAddr) { instr != null; instr = instr.getNextByAddr()) {
jode.flow.StructuredBlock block jode.flow.StructuredBlock block
= Opcodes.readOpcode(instr, this); = Opcodes.readOpcode(instr, this);
if (GlobalOptions.verboseLevel > 0 && instr.addr > mark) { if (GlobalOptions.verboseLevel > 0 && instr.getAddr() > mark) {
GlobalOptions.err.print('.'); GlobalOptions.err.print('.');
mark += 1000; mark += 1000;
} }
if (lastSequential && instr.tmpInfo == null if (lastSequential && instr.getTmpInfo() == null
/* Only merge with previous block, if this is sequential, /* Only merge with previous block, if this is sequential,
* too. * too.
* Why? doSequentialT2 does only handle sequential blocks. * Why? appendBlock does only handle sequential blocks.
*/ */
&& !instr.alwaysJumps && instr.succs == null) { && !instr.doesAlwaysJump() && instr.getSuccs() == null) {
lastBlock.doSequentialT2(block, instr.length); lastBlock.appendBlock(block, instr.getLength());
} else { } else {
if (instr.tmpInfo == null) if (instr.getTmpInfo() == null)
instr.tmpInfo = new FlowBlock instr.setTmpInfo(new FlowBlock(this, instr.getAddr()));
(this, instr.addr, instr.length); FlowBlock flowBlock = (FlowBlock) instr.getTmpInfo();
FlowBlock flowBlock = (FlowBlock) instr.tmpInfo; flowBlock.appendBlock(block, instr.getLength());
flowBlock.setBlock(block);
if (lastBlock != null) if (lastBlock != null)
lastBlock.setNextByAddr(flowBlock); lastBlock.setNextByAddr(flowBlock);
instr.tmpInfo = lastBlock = flowBlock; instr.setTmpInfo(lastBlock = flowBlock);
lastSequential = !instr.alwaysJumps && instr.succs == null; lastSequential = !instr.doesAlwaysJump()
&& instr.getSuccs() == null;
} }
} }
methodHeader = (FlowBlock) code.getFirstInstr().tmpInfo; methodHeader = (FlowBlock) code.getFirstInstr().getTmpInfo();
if (insertBlock != null) { if (insertBlock != null) {
insertBlock.setJump(new Jump(methodHeader)); insertBlock.setJump(new Jump(methodHeader));
FlowBlock insertFlowBlock = new FlowBlock(this, 0, 0); FlowBlock insertFlowBlock = new FlowBlock(this, 0);
insertFlowBlock.setBlock(insertBlock); insertFlowBlock.appendBlock(insertBlock, 0);
insertFlowBlock.setNextByAddr(methodHeader); insertFlowBlock.setNextByAddr(methodHeader);
methodHeader = insertFlowBlock; methodHeader = insertFlowBlock;
insertFlowBlock = null;
} }
excHandlers = new TransformExceptionHandlers(); excHandlers = new TransformExceptionHandlers();
for (int i=0; i<handlers.length; i++) { for (int i=0; i<handlers.length; i++) {
Type type = null; Type type = null;
FlowBlock start FlowBlock start
= (FlowBlock) handlers[i].start.tmpInfo; = (FlowBlock) handlers[i].start.getTmpInfo();
int endAddr = handlers[i].end.nextByAddr.addr; int endAddr = handlers[i].end.getNextByAddr().getAddr();
FlowBlock handler FlowBlock handler
= (FlowBlock) handlers[i].catcher.tmpInfo; = (FlowBlock) handlers[i].catcher.getTmpInfo();
if (handlers[i].type != null) if (handlers[i].type != null)
type = Type.tClass(handlers[i].type); type = Type.tClass(handlers[i].type);
@ -332,8 +336,8 @@ public class MethodAnalyzer implements Analyzer, Scope, ClassDeclarer {
} }
} }
for (Instruction instr = code.getFirstInstr(); for (Instruction instr = code.getFirstInstr();
instr != null; instr = instr.nextByAddr) instr != null; instr = instr.getNextByAddr())
instr.tmpInfo = null; instr.setTmpInfo(null);
if (GlobalOptions.verboseLevel > 0) if (GlobalOptions.verboseLevel > 0)
GlobalOptions.err.print('-'); GlobalOptions.err.print('-');

Loading…
Cancel
Save