function matchType()

in benchmarks/JetStream2/WSL/SPIR-V.js [56:104]


    function matchType(operandInfoKind, operand) {
        switch (operandInfoKind) {
            // FIXME: I'm not actually sure that Ids should be unsigned.
            case "IdResultType":
            case "IdResult":
            case "IdRef":
            case "IdScope":
            case "IdMemorySemantics":
            case "LiteralExtInstInteger":
                if (typeof operand != "number")
                    throw new Error("Operand needs to be a number");
                if ((operand >>> 0) != operand)
                    throw new Error("Operand needs to fit in an unsigned int");
                return;
            case "LiteralInteger":
                if (typeof operand != "number")
                    throw new Error("Operand needs to be a number");
                if ((operand | 0) != operand)
                    throw new Error("Operand needs to fit in an int");
                return;
            case "LiteralString":
                if (typeof operand != "string")
                    throw new Error("Operand needs to be a string");
                return;
            case "LiteralContextDependentNumber":
            case "LiteralSpecConstantOpInteger":
                if (typeof operand != "number")
                    throw new Error("Operand needs to be a number");
                if ((operand >>> 0) != operand && (operand | 0) != operand)
                    throw new Error("Operand needs to fit in an unsigned int or an int.");
                return;
        }
        let kind = result.kinds[operandInfoKind];
        if (kind) {
            if (operand instanceof Array) {
                if (kind.category != "BitEnum")
                    throw new Error("Passing an array to a " + kind.category + " operand");
                for (let operandItem of operand) {
                    if (kind[operandItem.enumerant] != operandItem)
                        throw new Error("" + operandItem.enumerant + " is not a member of " + operandInfoKind);
                }
                return;
            }
            if (kind[operand.enumerant] != operand)
                throw new Error("" + operand.enumerant + " is not a member of " + operandInfoKind);
            return;
        }
        throw new Error("Unknown type: " + operandInfoKind);
    }