Skip to content

Commit

Permalink
Make type validation use Module instead of Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Aug 14, 2024
1 parent bd17cf3 commit 0ed1a69
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 94 deletions.
25 changes: 2 additions & 23 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static com.dylibso.chicory.wasm.types.Value.REF_NULL_VALUE;

import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.TypeValidator;
import com.dylibso.chicory.wasm.exceptions.ChicoryException;
import com.dylibso.chicory.wasm.exceptions.InvalidException;
import com.dylibso.chicory.wasm.exceptions.MalformedException;
Expand Down Expand Up @@ -273,7 +274,7 @@ public Instance initialize(boolean start) {
+ funcType);
}
}
new TypeValidator().validate(i, this.function(i), this.types[funcType], this);
new TypeValidator(module).validate(i, function(i), types[funcType]);
}
}
}
Expand Down Expand Up @@ -358,31 +359,13 @@ public Value readGlobal(int idx) {
return globals[idx - importedGlobalsOffset].getValue();
}

public Global globalInitializer(int idx) {
if (idx < importedGlobalsOffset) {
return null;
}
if ((idx - importedGlobalsOffset) >= globalInitializers.length) {
throw new InvalidException("unknown global " + idx);
}
return globalInitializers[idx - importedGlobalsOffset];
}

public int globalCount() {
return globals.length;
}

public FunctionType type(int idx) {
if (idx >= types.length) {
throw new InvalidException("unknown type " + idx);
}
return types[idx];
}

public int typeCount() {
return types.length;
}

public int functionType(int idx) {
if (idx >= functionTypes.length) {
throw new InvalidException("unknown function " + idx);
Expand All @@ -408,10 +391,6 @@ public TableInstance table(int idx) {
return tables[idx - importedTablesOffset];
}

public DataSegment[] dataSegments() {
return dataSegments;
}

public Element element(int idx) {
if (idx < 0 || idx >= elements.length) {
throw new InvalidException("unknown elem segment " + idx);
Expand Down
Loading

0 comments on commit 0ed1a69

Please sign in to comment.