Exemplo n.º 1
0
static bool
DecodeBranch(FunctionDecoder& f, Expr expr, ExprType* type)
{
    MOZ_ASSERT(expr == Expr::Br || expr == Expr::BrIf);

    uint32_t relativeDepth;
    if (!f.d().readVarU32(&relativeDepth))
        return f.fail("expected relative depth");

    if (!f.branchWithType(relativeDepth, ExprType::Void))
        return f.fail("branch depth exceeds current nesting level");

    Expr value;
    if (!f.d().readExpr(&value))
        return f.fail("expected branch value");

    if (value != Expr::Nop)
        return f.fail("NYI: branch values");

    if (expr == Expr::BrIf) {
        ExprType actual;
        if (!DecodeExpr(f, &actual))
            return false;

        if (!CheckType(f, actual, ValType::I32))
            return false;

        *type = ExprType::Void;
    } else {
        *type = AnyType;
    }

    return true;
}
Exemplo n.º 2
0
static bool
DecodeBrTable(FunctionDecoder& f, ExprType* type)
{
    uint32_t tableLength;
    if (!f.d().readVarU32(&tableLength))
        return false;

    if (tableLength > MaxBrTableElems)
        return f.fail("too many br_table entries");

    for (uint32_t i = 0; i < tableLength; i++) {
        uint32_t depth;
        if (!f.d().readFixedU32(&depth))
            return f.fail("missing br_table entry");

        if (!f.branchWithType(depth, ExprType::Void))
            return f.fail("branch depth exceeds current nesting level");
    }

    uint32_t defaultDepth;
    if (!f.d().readFixedU32(&defaultDepth))
        return f.fail("expected default relative depth");

    if (!f.branchWithType(defaultDepth, ExprType::Void))
        return f.fail("branch depth exceeds current nesting level");

    ExprType actual;
    if (!DecodeExpr(f, &actual))
        return false;

    if (!CheckType(f, actual, ExprType::I32))
        return false;

    *type = AnyType;
    return true;
}