public class BranchSet extends Object
A logical expressions such as
if (i>= 0 && i%2 == 0 && i<100){}
gets translated into a sequence of bytecode level branches and targets. Which might look like the following.
a: if ? e +
b: if ? d |+
c: if ? e ||+
d: if ? out |v|+
e: ... v v|
... |
out: _instruction v
We need an algorithm for recognizing the underlying logical expression.
Essentially, given a set of branches, get the longest sequential sequence including the input set which target each other or _target. Branches can legally branch to another in the valid set, or to the fall through of the last in the valid set or to _target
So an
if(COND){IF_INSTRUCTIONS}else{ELSE_INSTUCTIONS}...will be
branch[?? branch]*, instructions*,goto,instruction*,target
and if(COND){IF_INSTRUCTIONS}...will be :-
branch[?? branch]*,instruction*,target
The psuedo code code the algorithm looks like this:
int n=0;
while (exp.length >1){
if (exp[n].target == exp[n+1].target){ #rule 1
replace exp[n] and exp[n+1] with a single expression representing 'exp[n] || exp[n+1]'
n=0;
}else if (exp[n].target == exp[n+1].next){ #rule 2
replace exp[n] and exp[n+1] with a single expression representing '!(exp[n]) && exp[n+1]
n=0;
}else{ #rule 3
n++;
}
}
result = !exp[0];
Modifier and Type | Class and Description |
---|---|
static class |
BranchSet.CompoundLogicalExpressionNode
A node in the expression tree representing a simple logical expression.
|
static class |
BranchSet.LogicalExpressionNode
Base abstract class used to hold information used to construct node tree for logical expressions.
|
static class |
BranchSet.SimpleLogicalExpressionNode
A node in the expression tree representing a simple logical expression.
|
Constructor and Description |
---|
BranchSet(InstructionSet.Branch _branch)
We construct a branch set with the 'last' branch.
|
Modifier and Type | Method and Description |
---|---|
List<InstructionSet.ConditionalBranch> |
getBranches() |
Instruction |
getFallThrough() |
InstructionSet.Branch |
getFirst() |
InstructionSet.Branch |
getLast() |
BranchSet.LogicalExpressionNode |
getLogicalExpression() |
Instruction |
getTarget() |
void |
unhook() |
public BranchSet(InstructionSet.Branch _branch)
_branch
are folded.
This will walk backwards until it finds a non-branch or until it finds a branch that does not below to this set._branch
- public List<InstructionSet.ConditionalBranch> getBranches()
public InstructionSet.Branch getFirst()
public InstructionSet.Branch getLast()
public void unhook()
public Instruction getTarget()
public Instruction getFallThrough()
public BranchSet.LogicalExpressionNode getLogicalExpression()
Copyright © 2021 Syncleus. All rights reserved.