예제 #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;
}
예제 #2
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");
}