mirror of
https://github.com/sirjonasxx/G-Wasm.git
synced 2024-11-26 18:30:52 +01:00
hi
This commit is contained in:
parent
fa41bb85e1
commit
9264d9292d
@ -33,4 +33,9 @@ public class TypeIdx extends WASMOpCode {
|
|||||||
public void setX(long x) {
|
public void setX(long x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return (obj instanceof TypeIdx && ((TypeIdx)obj).getX() == x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,41 +17,26 @@ import java.util.List;
|
|||||||
public class Function {
|
public class Function {
|
||||||
|
|
||||||
private FuncType funcType = null;
|
private FuncType funcType = null;
|
||||||
private List<ValType> locals = null;
|
private List<Locals> locals = null;
|
||||||
private Expression code = null;
|
private Expression code = null;
|
||||||
|
|
||||||
public Function(FuncType funcType, List<ValType> locals, Expression code) {
|
public Function(FuncType funcType, List<Locals> locals, Expression code) {
|
||||||
this.funcType = funcType;
|
this.funcType = funcType;
|
||||||
this.locals = locals;
|
this.locals = locals;
|
||||||
this.code = code;
|
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) {
|
public Function(Module module, FuncIdx funcIdx) {
|
||||||
this(module, (int)(funcIdx.getX()) - module.getImportSection().getTotalFuncImports());
|
funcType = module.getTypeSection().getByFuncIdx(funcIdx);
|
||||||
|
|
||||||
|
Func code = module.getCodeSection().getByIdx(funcIdx);
|
||||||
|
this.code = code.getExpression();
|
||||||
|
locals = code.getLocalss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuncIdx addToModule(Module module) {
|
public FuncIdx addToModule(Module module) {
|
||||||
TypeIdx typeIdx = module.getTypeSection().getTypeIdxForFuncType(funcType);
|
TypeIdx typeIdx = module.getTypeSection().getTypeIdxForFuncType(funcType);
|
||||||
ValType[] valTypeArr = locals.toArray(new ValType[0]);
|
Func func = new Func(locals, code);
|
||||||
Func func = new Func(valTypeArr, code);
|
|
||||||
|
|
||||||
module.getFunctionSection().getTypeIdxVector().add(typeIdx);
|
module.getFunctionSection().getTypeIdxVector().add(typeIdx);
|
||||||
module.getCodeSection().getCodesEntries().add(new Code(func));
|
module.getCodeSection().getCodesEntries().add(new Code(func));
|
||||||
@ -70,11 +55,22 @@ public class Function {
|
|||||||
this.funcType = funcType;
|
this.funcType = funcType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ValType> getLocals() {
|
public List<Locals> getLocals() {
|
||||||
return locals;
|
return locals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocals(List<ValType> locals) {
|
public List<ValType> getLocalsFloored() {
|
||||||
|
List<ValType> result = new ArrayList<>();
|
||||||
|
for (Locals loc : locals) {
|
||||||
|
for (int i = 0; i < loc.getAmount(); i++) {
|
||||||
|
result.add(loc.getValType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocals(List<Locals> locals) {
|
||||||
this.locals = locals;
|
this.locals = locals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user