Don't try and move jumps around in exceptions
This commit is contained in:
@@ -28,6 +28,9 @@ public class Code extends Attribute
|
|||||||
|
|
||||||
exceptions = new Exceptions(this);
|
exceptions = new Exceptions(this);
|
||||||
this.attributes = new Attributes(this);
|
this.attributes = new Attributes(this);
|
||||||
|
|
||||||
|
instructions.buildBlocks();
|
||||||
|
instructions.buildJumpGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ public class Block
|
|||||||
{
|
{
|
||||||
public Instruction begin, end;
|
public Instruction begin, end;
|
||||||
public List<Instruction> instructions = new ArrayList<>();
|
public List<Instruction> instructions = new ArrayList<>();
|
||||||
|
public List<Exception> exceptions = new ArrayList<>(); // is an instruction in the handlers try { }
|
||||||
|
public List<Exception> handlers = new ArrayList<>(); // first ins is a handler for exception
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ public class Instructions
|
|||||||
|
|
||||||
for (Instruction i : instructions)
|
for (Instruction i : instructions)
|
||||||
i.resolve();
|
i.resolve();
|
||||||
|
|
||||||
buildJumpGraph();
|
|
||||||
buildBlocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Instruction> getInstructions()
|
public List<Instruction> getInstructions()
|
||||||
@@ -84,6 +81,21 @@ public class Instructions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findExceptionInfo(Block block, Instruction i)
|
||||||
|
{
|
||||||
|
for (Exception e : code.getExceptions().getExceptions())
|
||||||
|
{
|
||||||
|
if (i.getPc() >= e.getStart().getPc() && i.getPc() < e.getEnd().getPc())
|
||||||
|
{
|
||||||
|
block.exceptions.add(e);
|
||||||
|
}
|
||||||
|
if (e.getHandler() == i)
|
||||||
|
{
|
||||||
|
block.handlers.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void buildBlocks()
|
public void buildBlocks()
|
||||||
{
|
{
|
||||||
for (Instruction i : instructions)
|
for (Instruction i : instructions)
|
||||||
@@ -97,6 +109,7 @@ public class Instructions
|
|||||||
{
|
{
|
||||||
current = new Block();
|
current = new Block();
|
||||||
current.begin = i;
|
current.begin = i;
|
||||||
|
findExceptionInfo(current, i);
|
||||||
}
|
}
|
||||||
i.block = current;
|
i.block = current;
|
||||||
current.instructions.add(i);
|
current.instructions.add(i);
|
||||||
|
|||||||
@@ -33,9 +33,12 @@ public class Jumps
|
|||||||
Block block = blocks.get(i);
|
Block block = blocks.get(i);
|
||||||
Block prev = i > 0 ? blocks.get(i - 1) : null;
|
Block prev = i > 0 ? blocks.get(i - 1) : null;
|
||||||
|
|
||||||
// only one thing jumps here
|
|
||||||
if (block.begin.from.size() == 1 && prev != null && prev.end.isTerminal())
|
if (block.begin.from.size() == 1 && prev != null && prev.end.isTerminal())
|
||||||
{
|
{
|
||||||
|
// not sure if this is right, just don't mess with blocks in exception ranges or directly handling them
|
||||||
|
if (block.exceptions.isEmpty() == false || block.handlers.isEmpty() == false || prev.exceptions.isEmpty() == false || prev.handlers.isEmpty() == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
Instruction from = block.begin.from.get(0); // this instruction jumps to block
|
Instruction from = block.begin.from.get(0); // this instruction jumps to block
|
||||||
|
|
||||||
if (from.block == block)
|
if (from.block == block)
|
||||||
|
|||||||
Reference in New Issue
Block a user