mirror of
https://github.com/sirjonasxx/G-Wasm.git
synced 2024-11-22 16:30:51 +01:00
some tools
This commit is contained in:
parent
b840094b25
commit
fa41bb85e1
@ -3,6 +3,7 @@ package wasm.disassembly.modules.sections.code;
|
||||
import wasm.disassembly.InvalidOpCodeException;
|
||||
import wasm.disassembly.conventions.Vector;
|
||||
import wasm.disassembly.modules.Module;
|
||||
import wasm.disassembly.modules.indices.FuncIdx;
|
||||
import wasm.disassembly.modules.sections.Section;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
@ -32,6 +33,13 @@ public class CodeSection extends Section {
|
||||
codesEntries.assemble(out);
|
||||
}
|
||||
|
||||
public Code getCodeByIdx(FuncIdx funcIdx) {
|
||||
return codesEntries.getElements().get((int)(funcIdx.getX()) - module.getImportSection().getTotalFuncImports());
|
||||
}
|
||||
|
||||
public Func getByIdx(FuncIdx funcIdx) {
|
||||
return getCodeByIdx(funcIdx).getCode();
|
||||
}
|
||||
|
||||
public List<Code> getCodesEntries() {
|
||||
return codesEntries.getElements();
|
||||
|
@ -3,8 +3,11 @@ package wasm.disassembly.modules.sections.function;
|
||||
import wasm.disassembly.InvalidOpCodeException;
|
||||
import wasm.disassembly.conventions.Vector;
|
||||
import wasm.disassembly.modules.Module;
|
||||
import wasm.disassembly.modules.indices.FuncIdx;
|
||||
import wasm.disassembly.modules.indices.TypeIdx;
|
||||
import wasm.disassembly.modules.sections.Section;
|
||||
import wasm.disassembly.modules.sections.code.Code;
|
||||
import wasm.disassembly.modules.sections.code.Func;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
@ -33,6 +36,10 @@ public class FunctionSection extends Section {
|
||||
typeIdxVector.assemble(out);
|
||||
}
|
||||
|
||||
public TypeIdx getByIdx(FuncIdx funcIdx) {
|
||||
return typeIdxVector.getElements().get((int)(funcIdx.getX()) - module.getImportSection().getTotalFuncImports());
|
||||
}
|
||||
|
||||
public List<TypeIdx> getTypeIdxVector() {
|
||||
return typeIdxVector.getElements();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ImportSection extends Section {
|
||||
@ -75,6 +76,14 @@ public class ImportSection extends Section {
|
||||
return newFuncIdxs;
|
||||
}
|
||||
|
||||
public FuncIdx importFunction(Import function) throws InvalidOpCodeException {
|
||||
return importFunctions(Collections.singletonList(function)).get(0);
|
||||
}
|
||||
|
||||
public Import getByIdx(FuncIdx funcIdx) {
|
||||
return imports.getElements().get((int)funcIdx.getX());
|
||||
}
|
||||
|
||||
public int getTotalFuncImports() {
|
||||
return totalFuncImports;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package wasm.disassembly.modules.sections.type;
|
||||
import wasm.disassembly.InvalidOpCodeException;
|
||||
import wasm.disassembly.conventions.Vector;
|
||||
import wasm.disassembly.modules.Module;
|
||||
import wasm.disassembly.modules.indices.FuncIdx;
|
||||
import wasm.disassembly.modules.indices.TypeIdx;
|
||||
import wasm.disassembly.modules.sections.Section;
|
||||
import wasm.disassembly.types.FuncType;
|
||||
@ -34,6 +35,10 @@ public class TypeSection extends Section {
|
||||
functionTypes.assemble(out);
|
||||
}
|
||||
|
||||
public FuncType getByFuncIdx(FuncIdx funcIdx) {
|
||||
return getByTypeIdx(module.getFunctionSection().getByIdx(funcIdx));
|
||||
}
|
||||
|
||||
public List<FuncType> getFunctionTypes() {
|
||||
return functionTypes.getElements();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user