mirror of
https://github.com/sirjonasxx/G-Wasm.git
synced 2024-11-22 16:30:51 +01:00
stuff blabla
This commit is contained in:
parent
e03df8be08
commit
db981325c7
@ -46,4 +46,12 @@ public class Locals extends WASMOpCode {
|
||||
public void setValType(ValType valType) {
|
||||
this.valType = valType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Locals)) return false;
|
||||
Locals other = (Locals) obj;
|
||||
return amount == other.amount && valType.val == other.valType.val;
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ public class TypeSection extends Section {
|
||||
return functionTypes.getElements();
|
||||
}
|
||||
|
||||
public FuncType getByTypeIdx(TypeIdx typeIdx) {
|
||||
return functionTypes.getElements().get((int)(typeIdx.getX()));
|
||||
}
|
||||
|
||||
public void setFunctionTypes(List<FuncType> functionTypes) {
|
||||
this.functionTypes = new Vector<>(functionTypes);
|
||||
}
|
||||
|
@ -60,4 +60,9 @@ public class FuncType extends WASMOpCode {
|
||||
return parameterType.equals(other.parameterType) &&
|
||||
resultType.equals(other.resultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return parameterType + " -> " + resultType;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ResultType extends WASMOpCode {
|
||||
|
||||
@ -60,4 +62,9 @@ public class ResultType extends WASMOpCode {
|
||||
ResultType other = (ResultType) obj;
|
||||
return vector.getElements().equals(other.vector.getElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + vector.getElements().stream().map(Enum::name).collect(Collectors.joining(" ")) + ")";
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package wasm.disassembly.modules.misc;
|
||||
package wasm.misc;
|
||||
|
||||
import wasm.disassembly.instructions.Expression;
|
||||
import wasm.disassembly.modules.Module;
|
||||
@ -6,16 +6,19 @@ import wasm.disassembly.modules.indices.FuncIdx;
|
||||
import wasm.disassembly.modules.indices.TypeIdx;
|
||||
import wasm.disassembly.modules.sections.code.Code;
|
||||
import wasm.disassembly.modules.sections.code.Func;
|
||||
import wasm.disassembly.modules.sections.code.Locals;
|
||||
import wasm.disassembly.types.FuncType;
|
||||
import wasm.disassembly.types.ValType;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Function {
|
||||
|
||||
private FuncType funcType;
|
||||
private List<ValType> locals;
|
||||
private Expression code;
|
||||
private FuncType funcType = null;
|
||||
private List<ValType> locals = null;
|
||||
private Expression code = null;
|
||||
|
||||
public Function(FuncType funcType, List<ValType> locals, Expression code) {
|
||||
this.funcType = funcType;
|
||||
@ -23,6 +26,28 @@ public class Function {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Function(Module module, int funcId) {
|
||||
if (funcId < 0) return;
|
||||
|
||||
TypeIdx typeIdx = module.getFunctionSection().getTypeIdxVector().get(funcId);
|
||||
funcType = module.getTypeSection().getByTypeIdx(typeIdx);
|
||||
|
||||
Func code = module.getCodeSection().getCodesEntries().get(funcId).getCode();
|
||||
this.code = code.getExpression();
|
||||
|
||||
locals = new ArrayList<>();
|
||||
List<Locals> localss = code.getLocalss();
|
||||
for (Locals loc : localss) {
|
||||
for (int i = 0; i < loc.getAmount(); i++) {
|
||||
locals.add(loc.getValType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Function(Module module, FuncIdx funcIdx) {
|
||||
this(module, (int)(funcIdx.getX()) - module.getImportSection().getTotalFuncImports());
|
||||
}
|
||||
|
||||
public FuncIdx addToModule(Module module) {
|
||||
TypeIdx typeIdx = module.getTypeSection().getTypeIdxForFuncType(funcType);
|
||||
ValType[] valTypeArr = locals.toArray(new ValType[0]);
|
Loading…
Reference in New Issue
Block a user