void validateBranchDepth(uintp depth) const { VALIDATE_INDEX(depth,controlStack.size()); if(depth >= controlStack.size()) { throw ValidationException("invalid branch depth"); } }
void call_indirect(CallIndirectImm imm) { VALIDATE_INDEX(imm.typeIndex,module.types.size()); VALIDATE_UNLESS("call_indirect in module without default function table: ",moduleContext.numTables==0); const FunctionType* calleeType = module.types[imm.typeIndex]; popAndValidateOperand(ValueType::i32); popAndValidateOperands(calleeType->parameters.data(),calleeType->parameters.size()); push(calleeType->ret); }
void call_indirect(CallIndirectImm imm) { VALIDATE_INDEX(imm.type.index,module.types.size()); VALIDATE_UNLESS("call_indirect is only valid if there is a default function table: ",module.tables.size()==0); const FunctionType* calleeType = module.types[imm.type.index]; popAndValidateOperand("call_indirect function index",ValueType::i32); popAndValidateOperands("call_indirect arguments",calleeType->parameters.data(),(Uptr)calleeType->parameters.size()); pushOperand(calleeType->ret); }
ValueType validateGlobalIndex(const Module& module,Uptr globalIndex,bool mustBeMutable,bool mustBeImmutable,bool mustBeImport,const char* context) { VALIDATE_INDEX(globalIndex,module.globals.size()); const GlobalType& globalType = module.globals.getType(globalIndex); if(mustBeMutable && !globalType.isMutable) { throw ValidationException("attempting to mutate immutable global"); } else if(mustBeImport && globalIndex >= module.globals.imports.size()) { throw ValidationException("global variable initializer expression may only access imported globals"); } else if(mustBeImmutable && globalType.isMutable) { throw ValidationException("global variable initializer expression may only access immutable globals"); } return globalType.valueType; }
ValueType validateGlobalIndex(uintp globalIndex,bool mustBeMutable,bool mustBeImmutable,bool mustBeImport,const char* context) { assert(numImportedGlobals != UINTPTR_MAX); VALIDATE_INDEX(globalIndex,globals.size()); const GlobalType& globalType = globals[globalIndex]; if(mustBeMutable && !globalType.isMutable) { throw ValidationException("attempting to mutate immutable global"); } else if(mustBeImport && globalIndex >= numImportedGlobals) { throw ValidationException("global variable initializer expression may only access imported globals"); } else if(mustBeImmutable && globalType.isMutable) { throw ValidationException("global variable initializer expression may only access immutable globals"); } return globalType.valueType; }
ValueType validateLocalIndex(uintp localIndex) { VALIDATE_INDEX(localIndex,locals.size()); return locals[localIndex]; }
const FunctionType* validateFunctionIndex(uintp functionIndex) { VALIDATE_INDEX(functionIndex,functions.size()); return functions[functionIndex]; }
const FunctionType* validateFunctionIndex(const Module& module,Uptr functionIndex) { VALIDATE_INDEX(functionIndex,module.functions.size()); return module.types[module.functions.getType(functionIndex).index]; }