Skip to content

Commit

Permalink
feat(objectionary#344): simplify the search of unsupported opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 6, 2024
1 parent 4c54bd0 commit 0705c62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/main/java/org/eolang/opeo/SelectiveDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import com.jcabi.log.Logger;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.eolang.opeo.decompilation.Decompiler;
import org.eolang.opeo.decompilation.WithoutAliases;
Expand Down Expand Up @@ -118,8 +120,8 @@ public void decompile() {
this.storage.all().parallel().forEach(
entry -> {
final XmirEntry res;
final List<String> opcodes = entry.xpath(this.unsupportedOpcodes());
final List<String> trycatches = entry.xpath(SelectiveDecompiler.trycatches());
final Set<String> opcodes = this.unsupported(entry);
if (opcodes.isEmpty() && trycatches.isEmpty()) {
res = entry.transform(
xml -> new WithoutAliases(
Expand All @@ -143,16 +145,20 @@ public void decompile() {
}

/**
* Xpath to find all opcodes that are not supported.
* @return Xpath.
* Find all opcodes that are not supported.
* @param entry XMIR entry.
* @return Set of unsupported opcodes.
*/
private String unsupportedOpcodes() {
return String.format(
"//o[@base='opcode' and not(%s)]/@name",
Arrays.stream(this.supported)
.map(s -> String.format("substring-before(concat(@name, '-'), '-') = '%s'", s))
.collect(Collectors.joining(" or "))
);
private Set<String> unsupported(final XmirEntry entry) {
final Set<String> all = entry.xpath(
"//o[@base='opcode']/@name")
.stream()
.map(s -> String.format("%s%s", s, "-"))
.map(s -> s.substring(0, s.indexOf('-')))
.collect(Collectors.toSet());
final Set<String> sup = Arrays.stream(this.supported).collect(Collectors.toSet());
all.removeAll(sup);
return all;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<o base="int" data="bytes" line="1356216656">00 00 00 00 00 00 00 15</o>
<o base="int" data="bytes" line="1379763138">00 00 00 00 00 00 00 01</o>
</o>
<o base="opcode" line="999" name="NEWARRAY-22FD0B">
<o base="opcode" line="999" name="NEWARRAY">
<o base="int" data="bytes" line="345712082">00 00 00 00 00 00 00 BC</o>
<o base="int" data="bytes" line="822390983">00 00 00 00 00 00 00 08</o>
</o>
Expand Down

0 comments on commit 0705c62

Please sign in to comment.