MCPcopy Create free account
hub / github.com/Hiro420/NikkeTools / Code

Class Code

UnLuac/src/unluac/decompile/Code.java:6–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import unluac.parse.LFunction;
5
6public class Code {
7
8 private final CodeExtract extractor;
9 private final OpcodeMap map;
10 private final int[] code;
11 private final boolean[] extraByte;
12 private final boolean[] upvalue;
13 public final int length;
14
15 public Code(LFunction function) {
16 this.code = function.code;
17 this.length = code.length;
18 map = function.header.opmap;
19 extractor = function.header.extractor;
20 extraByte = new boolean[length];
21 for(int i = 0; i < length; i++) {
22 int line = i + 1;
23 Op op = op(line);
24 extraByte[i] = op != null && op.hasExtraByte(codepoint(line), extractor);
25 }
26 upvalue = new boolean[length];
27 if(function.header.version.upvaluedeclarationtype.get() == Version.UpvalueDeclarationType.INLINE) {
28 for(int i = 0; i < length; i++) {
29 int line = i + 1;
30 if(op(line) == Op.CLOSURE) {
31 int f = Bx(line);
32 if(f < function.functions.length) {
33 int nups = function.functions[f].numUpvalues;
34 for(int j = 1; j <= nups; j++) {
35 if(i + j < length) {
36 upvalue[i + j] = true;
37 }
38 }
39 }
40 }
41 }
42 }
43 }
44
45 public CodeExtract getExtractor() {
46 return extractor;
47 }
48
49 //public boolean reentered = false;
50
51 /**
52 * Returns the operation indicated by the instruction at the given line.
53 */
54 public Op op(int line) {
55 /*if(!reentered) {
56 reentered = true;
57 System.out.println("line " + line + ": " + toString(line));
58 reentered = false;
59 }*/
60 if(line >= 2 && extraByte[line - 2]) {
61 return Op.EXTRABYTE;
62 } else {
63 return map.get(opcode(line));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected