Exemplo n.º 1
0
static bool
RenderImport(WasmRenderContext& c, AstImport& import, const AstModule::SigVector& sigs)
{
    const AstSig* sig = sigs[import.funcSig().index()];
    if (!RenderIndent(c))
        return false;
    if (!c.buffer.append("(import "))
        return false;
    if (!RenderName(c, import.name()))
        return false;
    if (!c.buffer.append(" \""))
        return false;

    const AstName& moduleName = import.module();
    if (!RenderEscapedString(c, moduleName))
        return false;

    if (!c.buffer.append("\" \""))
        return false;

    const AstName& fieldName = import.field();
    if (!RenderEscapedString(c, fieldName))
        return false;

    if (!c.buffer.append("\""))
        return false;

    if (!RenderSignature(c, *sig))
        return false;
    if (!c.buffer.append(")\n"))
        return false;

    return true;
}
Exemplo n.º 2
0
static bool
AstDecodeCallImport(AstDecodeContext& c)
{
    uint32_t importIndex;
    uint32_t arity;
    if (!c.iter().readCallImport(&importIndex, &arity))
        return false;

    if (importIndex >= c.module().imports().length())
        return c.iter().fail("import index out of range");

    AstImport* import = c.module().imports()[importIndex];
    AstSig* sig = c.module().sigs()[import->sig().index()];
    AstRef funcRef;
    if (!AstDecodeGenerateRef(c, AstName(MOZ_UTF16("$import$"), 8), importIndex, &funcRef))
        return false;

    AstExprVector args(c.lifo);
    if (!AstDecodeCallArgs(c, arity, *sig, &args))
        return false;

    if (!AstDecodeCallReturn(c, *sig))
        return false;

    uint32_t argsLength = args.length();
    AstCall* call = new(c.lifo) AstCall(Expr::CallImport, funcRef, Move(args));
    if (!call)
        return false;

    c.iter().setResult(AstDecodeStackItem(call, argsLength));
    return true;
}
Exemplo n.º 3
0
static bool
RenderImport(WasmRenderContext& c, AstImport& import, const AstModule& module)
{
    if (!RenderIndent(c))
        return false;
    if (!c.buffer.append("(import "))
        return false;
    if (!RenderName(c, import.name()))
        return false;
    if (!c.buffer.append(" \""))
        return false;

    const AstName& moduleName = import.module();
    if (!RenderEscapedString(c, moduleName))
        return false;

    if (!c.buffer.append("\" \""))
        return false;

    const AstName& fieldName = import.field();
    if (!RenderEscapedString(c, fieldName))
        return false;

    if (!c.buffer.append("\" "))
        return false;

    switch (import.kind()) {
      case DefinitionKind::Function: {
        const AstSig* sig = module.sigs()[import.funcSig().index()];
        if (!RenderSignature(c, *sig))
            return false;
        break;
      }
      case DefinitionKind::Table: {
        if (!RenderResizableTable(c, import.limits()))
            return false;
        break;
      }
      case DefinitionKind::Memory: {
        if (!RenderResizableMemory(c, import.limits()))
            return false;
        break;
      }
      case DefinitionKind::Global: {
        const AstGlobal& glob = import.global();
        if (!RenderGlobal(c, glob, /* inImport */ true))
            return false;
        break;
      }
    }

    return c.buffer.append(")\n");
}