-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.5.1 - Fix 'switch' statement decompilation. Start work on 'if' stat…
…ements.
- Loading branch information
1 parent
2497bc4
commit 3653372
Showing
14 changed files
with
488 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package twg2.jbcm.ir; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import twg2.jbcm.toSource.SwitchFlow; | ||
|
||
/** | ||
* @author TeamworkGuy2 | ||
* @since 2020-12-05 | ||
*/ | ||
public class Switch { | ||
public List<SwitchCase> switchCases; | ||
protected List<SwitchCase> finishedCases; | ||
public SwitchCase switchDefault; | ||
public int switchInstSize; | ||
public int switchEndIdx; | ||
/** whether all the cases in this switch return/throw before the next case starts (see {@link SwitchFlow#isSwitchSimplePacked(List, SwitchCase, byte[])}) */ | ||
public boolean isReturnPacked; | ||
|
||
|
||
public Switch(List<SwitchCase> switchCases, SwitchCase switchDefault) { | ||
this.switchCases = switchCases; | ||
this.switchDefault = switchDefault; | ||
this.finishedCases = new ArrayList<SwitchCase>(); | ||
} | ||
|
||
|
||
public void finish(SwitchCase switchCase) { | ||
switchCase.finish(); | ||
finishedCases.add(switchCase); | ||
} | ||
|
||
|
||
public boolean isFinished() { | ||
return finishedCases.size() == switchCases.size() + 1; // + 1 for default case | ||
} | ||
|
||
|
||
public static Switch loadTableSwitch(int i, byte[] instr) { | ||
var dstCases = new ArrayList<SwitchCase>(); | ||
var dstSwitchDefault = new AtomicReference<SwitchCase>(); | ||
int newI = SwitchFlow.loadTableSwitch(i, instr, dstCases, dstSwitchDefault); | ||
var inst = new Switch(dstCases, dstSwitchDefault.get()); | ||
int endIdx = SwitchFlow.commonSwitchEndIndex(inst.switchCases, inst.switchDefault, instr); | ||
if(endIdx == -1) { | ||
endIdx = SwitchFlow.maxSwitchCodeFlowIndex(inst.switchCases, inst.switchDefault, instr); | ||
if(endIdx > -1) { | ||
inst.isReturnPacked = true; | ||
} | ||
} | ||
inst.switchEndIdx = endIdx; | ||
inst.switchInstSize = newI; | ||
return inst; | ||
} | ||
|
||
|
||
public static Switch loadLookupSwitch(int i, byte[] instr) { | ||
var dstCases = new ArrayList<SwitchCase>(); | ||
var dstSwitchDefault = new AtomicReference<SwitchCase>(); | ||
int newI = SwitchFlow.loadLookupSwitch(i, instr, dstCases, dstSwitchDefault); | ||
var inst = new Switch(dstCases, dstSwitchDefault.get()); | ||
int endIdx = SwitchFlow.commonSwitchEndIndex(inst.switchCases, inst.switchDefault, instr); | ||
if(endIdx == -1) { | ||
endIdx = SwitchFlow.maxSwitchCodeFlowIndex(inst.switchCases, inst.switchDefault, instr); | ||
if(endIdx > -1) { | ||
inst.isReturnPacked = true; | ||
} | ||
} | ||
inst.switchEndIdx = endIdx; | ||
inst.switchInstSize = newI; | ||
return inst; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.