Exemple #1
0
static bool
EncodeFunc(Encoder& e, WasmAstFunc& func)
{
    if (!e.writeCString(FuncSubsection))
        return false;

    size_t offset;
    if (!e.startSection(&offset))
        return false;

    if (!e.writeVarU32(func.varTypes().length()))
        return false;

    for (ValType type : func.varTypes()) {
        if (!e.writeValType(type))
            return false;
    }

    if (func.maybeBody()) {
        if (!EncodeExpr(e, *func.maybeBody()))
            return false;
    } else {
        if (!e.writeExpr(Expr::Nop))
            return false;
    }

    e.finishSection(offset);

    return true;
}
Exemple #2
0
static bool
EncodeSignatureSection(Encoder& e, WasmAstModule& module)
{
    if (module.sigs().empty())
        return true;

    if (!e.writeCString(SigSection))
        return false;

    size_t offset;
    if (!e.startSection(&offset))
        return false;

    if (!e.writeVarU32(module.sigs().length()))
        return false;

    for (WasmAstSig* sig : module.sigs()) {
        if (!e.writeVarU32(sig->args().length()))
            return false;

        if (!e.writeExprType(sig->ret()))
            return false;

        for (ValType t : sig->args()) {
            if (!e.writeValType(t))
                return false;
        }
    }

    e.finishSection(offset);
    return true;
}
Exemple #3
0
static bool
EncodeCodeSection(Encoder& e, WasmAstModule& module)
{
    if (module.funcs().empty())
        return true;

    if (!e.writeCString(CodeSection))
        return false;

    size_t offset;
    if (!e.startSection(&offset))
        return false;

    if (!e.writeVarU32(module.funcs().length()))
        return false;

    for (WasmAstFunc* func : module.funcs()) {
        if (!EncodeFunc(e, *func))
            return false;
    }

    e.finishSection(offset);
    return true;
}
Exemple #4
0
static bool
EncodeExportSection(Encoder& e, WasmAstModule& module)
{
    if (module.exports().empty())
        return true;

    if (!e.writeCString(ExportSection))
        return false;

    size_t offset;
    if (!e.startSection(&offset))
        return false;

    if (!e.writeVarU32(module.exports().length()))
        return false;

    for (WasmAstExport* exp : module.exports()) {
        if (!EncodeExport(e, *exp))
            return false;
    }

    e.finishSection(offset);
    return true;
}
Exemple #5
0
static bool
EncodeDeclarationSection(Encoder& e, WasmAstModule& module)
{
    if (module.funcs().empty())
        return true;

    if (!e.writeCString(DeclSection))
        return false;

    size_t offset;
    if (!e.startSection(&offset))
        return false;

    if (!e.writeVarU32(module.funcs().length()))
        return false;

    for (WasmAstFunc* func : module.funcs()) {
        if (!e.writeVarU32(func->sigIndex()))
            return false;
    }

    e.finishSection(offset);
    return true;
}