当前位置: 首页>>代码示例>>C++>>正文


C++ ModuleGenerator类代码示例

本文整理汇总了C++中ModuleGenerator的典型用法代码示例。如果您正苦于以下问题:C++ ModuleGenerator类的具体用法?C++ ModuleGenerator怎么用?C++ ModuleGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ModuleGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DecodeExport

static bool
DecodeExport(JSContext* cx, Decoder& d, ModuleGenerator& mg, ExportMap* exportMap)
{
    if (!d.readCStringIf(FuncSubsection))
        return Fail(cx, d, "expected 'func' tag");

    uint32_t funcIndex;
    if (!d.readVarU32(&funcIndex))
        return Fail(cx, d, "expected export internal index");

    if (funcIndex >= mg.numFuncSigs())
        return Fail(cx, d, "export function index out of range");

    uint32_t exportIndex;
    if (!mg.declareExport(funcIndex, &exportIndex))
        return false;

    MOZ_ASSERT(exportIndex <= exportMap->exportNames.length());
    if (exportIndex == exportMap->exportNames.length()) {
        UniqueChars funcName(JS_smprintf("%u", unsigned(funcIndex)));
        if (!funcName || !exportMap->exportNames.emplaceBack(Move(funcName)))
            return false;
    }

    if (!exportMap->fieldsToExports.append(exportIndex))
        return false;

    const char* chars;
    if (!d.readCString(&chars))
        return Fail(cx, d, "expected export external name string");

    return exportMap->fieldNames.emplaceBack(DuplicateString(chars));
}
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:33,代码来源:Wasm.cpp

示例2: GenerateThrowStub

// If an exception is thrown, simply pop all frames (since asm.js does not
// contain try/catch). To do this:
//  1. Restore 'sp' to it's value right after the PushRegsInMask in GenerateEntry.
//  2. PopRegsInMask to restore the caller's non-volatile registers.
//  3. Return (to CallAsmJS).
static bool
GenerateThrowStub(ModuleGenerator& mg, Label* throwLabel)
{
    MacroAssembler& masm = mg.masm();

    masm.haltingAlign(CodeAlignment);
    Offsets offsets;
    offsets.begin = masm.currentOffset();
    masm.bind(throwLabel);

    // We are about to pop all frames in this WasmActivation. Set fp to null to
    // maintain the invariant that fp is either null or pointing to a valid
    // frame.
    Register scratch = ABIArgGenerator::NonArgReturnReg0;
    masm.loadWasmActivation(scratch);
    masm.storePtr(ImmWord(0), Address(scratch, WasmActivation::offsetOfFP()));

    masm.setFramePushed(FramePushedForEntrySP);
    masm.loadStackPtr(Address(scratch, WasmActivation::offsetOfEntrySP()));
    masm.Pop(scratch);
    masm.PopRegsInMask(NonVolatileRegs);
    MOZ_ASSERT(masm.framePushed() == 0);

    masm.mov(ImmWord(0), ReturnReg);
    masm.ret();

    if (masm.oom())
        return false;

    offsets.end = masm.currentOffset();
    return mg.defineInlineStub(offsets);
}
开发者ID:tungmangtdh3,项目名称:gecko-dev,代码行数:37,代码来源:WasmStubs.cpp

示例3: DecodeCodeSection

static bool
DecodeCodeSection(const ModuleEnvironment& env, DecoderT& d, ModuleGenerator& mg)
{
    if (!env.codeSection) {
        if (env.numFuncDefs() != 0)
            return d.fail("expected code section");

        return mg.finishFuncDefs();
    }

    uint32_t numFuncDefs;
    if (!d.readVarU32(&numFuncDefs))
        return d.fail("expected function body count");

    if (numFuncDefs != env.numFuncDefs())
        return d.fail("function body count does not match function signature count");

    for (uint32_t funcDefIndex = 0; funcDefIndex < numFuncDefs; funcDefIndex++) {
        if (!DecodeFunctionBody(d, mg, env.numFuncImports() + funcDefIndex))
            return false;
    }

    if (!d.finishSection(*env.codeSection, "code"))
        return false;

    return mg.finishFuncDefs();
}
开发者ID:luke-chang,项目名称:gecko-1,代码行数:27,代码来源:WasmCompile.cpp

示例4: GenerateOutOfBoundsStub

// Generate a stub that is jumped to from an out-of-bounds heap access when
// there are throwing semantics. This stub calls a C++ function to report an
// error and then jumps to the throw stub to pop the activation.
static bool
GenerateOutOfBoundsStub(ModuleGenerator& mg, Label* throwLabel)
{
    MacroAssembler& masm = mg.masm();

    masm.haltingAlign(CodeAlignment);
    Offsets offsets;
    offsets.begin = masm.currentOffset();
    masm.bind(masm.asmOnOutOfBoundsLabel());

    // sp can be anything at this point, so ensure it is aligned when calling
    // into C++.  We unconditionally jump to throw so don't worry about restoring sp.
    masm.andToStackPtr(Imm32(~(ABIStackAlignment - 1)));

    // OnOutOfBounds always throws.
    masm.assertStackAlignment(ABIStackAlignment);
    masm.call(SymbolicAddress::OnOutOfBounds);
    masm.jump(throwLabel);

    if (masm.oom())
        return false;

    offsets.end = masm.currentOffset();
    return mg.defineOutOfBoundsStub(offsets);
}
开发者ID:tungmangtdh3,项目名称:gecko-dev,代码行数:28,代码来源:WasmStubs.cpp

示例5: DecodeFunctionBodies

static bool
DecodeFunctionBodies(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t sectionStart;
    if (!d.startSection(FunctionBodiesId, &sectionStart))
        return Fail(cx, d, "failed to start section");

    if (sectionStart == Decoder::NotStarted) {
        if (mg.numFuncSigs() != 0)
            return Fail(cx, d, "expected function bodies");

        return mg.finishFuncDefs();
    }

    uint32_t numFuncBodies;
    if (!d.readVarU32(&numFuncBodies))
        return Fail(cx, d, "expected function body count");

    if (numFuncBodies != mg.numFuncSigs())
        return Fail(cx, d, "function body count does not match function signature count");

    for (uint32_t funcIndex = 0; funcIndex < numFuncBodies; funcIndex++) {
        if (!DecodeFunctionBody(cx, d, mg, funcIndex))
            return false;
    }

    if (!d.finishSection(sectionStart))
        return Fail(cx, d, "function section byte size mismatch");

    return mg.finishFuncDefs();
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:34,代码来源:Wasm.cpp

示例6: GenerateStackOverflowStub

// Generate a stub that is called immediately after the prologue when there is a
// stack overflow. This stub calls a C++ function to report the error and then
// jumps to the throw stub to pop the activation.
static bool
GenerateStackOverflowStub(ModuleGenerator& mg, Label* throwLabel)
{
    MacroAssembler& masm = mg.masm();

    masm.haltingAlign(CodeAlignment);
    Offsets offsets;
    offsets.begin = masm.currentOffset();
    masm.bind(masm.asmStackOverflowLabel());

    // If we reach here via the non-profiling prologue, WasmActivation::fp has
    // not been updated. To enable stack unwinding from C++, store to it now. If
    // we reached here via the profiling prologue, we'll just store the same
    // value again. Do not update AsmJSFrame::callerFP as it is not necessary in
    // the non-profiling case (there is no return path from this point) and, in
    // the profiling case, it is already correct.
    Register activation = ABIArgGenerator::NonArgReturnReg0;
    masm.loadWasmActivation(activation);
    masm.storePtr(masm.getStackPointer(), Address(activation, WasmActivation::offsetOfFP()));

    // Prepare the stack for calling C++.
    if (uint32_t d = StackDecrementForCall(ABIStackAlignment, sizeof(AsmJSFrame), ShadowStackSpace))
        masm.subFromStackPtr(Imm32(d));

    // No need to restore the stack; the throw stub pops everything.
    masm.assertStackAlignment(ABIStackAlignment);
    masm.call(SymbolicAddress::ReportOverRecursed);
    masm.jump(throwLabel);

    if (masm.oom())
        return false;

    offsets.end = masm.currentOffset();
    return mg.defineInlineStub(offsets);
}
开发者ID:tungmangtdh3,项目名称:gecko-dev,代码行数:38,代码来源:WasmStubs.cpp

示例7: DecodeFunctionBody

static bool
DecodeFunctionBody(JSContext* cx, Decoder& d, ModuleGenerator& mg, uint32_t funcIndex)
{
    int64_t before = PRMJ_Now();

    uint32_t bodySize;
    if (!d.readVarU32(&bodySize))
        return Fail(cx, d, "expected number of function body bytes");

    if (d.bytesRemain() < bodySize)
        return Fail(cx, d, "function body length too big");

    const uint8_t* bodyBegin = d.currentPosition();
    const uint8_t* bodyEnd = bodyBegin + bodySize;

    FunctionGenerator fg;
    if (!mg.startFuncDef(d.currentOffset(), &fg))
        return false;

    ValTypeVector locals;
    if (!locals.appendAll(mg.funcSig(funcIndex).args()))
        return false;

    if (!DecodeLocalEntries(d, &locals))
        return Fail(cx, d, "failed decoding local entries");

    for (ValType type : locals) {
        if (!CheckValType(cx, d, type))
            return false;
    }

    FunctionDecoder f(cx, d, mg, fg, funcIndex, locals);

    ExprType type = ExprType::Void;

    while (d.currentPosition() < bodyEnd) {
        if (!DecodeExpr(f, &type))
            return false;
    }

    if (!CheckType(f, type, f.sig().ret()))
        return false;

    if (d.currentPosition() != bodyEnd)
        return Fail(cx, d, "function body length mismatch");

    if (!fg.bytes().resize(bodySize))
        return false;

    memcpy(fg.bytes().begin(), bodyBegin, bodySize);

    int64_t after = PRMJ_Now();
    unsigned generateTime = (after - before) / PRMJ_USEC_PER_MSEC;

    return mg.finishFuncDef(funcIndex, generateTime, &fg);
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:56,代码来源:Wasm.cpp

示例8: DecodeMemoryExport

static bool
DecodeMemoryExport(JSContext* cx, Decoder& d, ModuleGenerator& mg, CStringSet* dupSet)
{
    if (!mg.usesHeap())
        return Fail(cx, d, "cannot export memory with no memory section");

    UniqueChars fieldName = DecodeFieldName(cx, d, dupSet);
    if (!fieldName)
        return false;

    return mg.addMemoryExport(Move(fieldName));
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:12,代码来源:Wasm.cpp

示例9: DecodeMemory

static bool
DecodeMemory(JSContext* cx, Decoder& d, ModuleGenerator& mg, MutableHandle<ArrayBufferObject*> heap)
{
    uint32_t sectionStart;
    if (!d.startSection(MemoryId, &sectionStart))
        return Fail(cx, d, "failed to start section");
    if (sectionStart == Decoder::NotStarted)
        return true;

    uint32_t initialSizePages;
    if (!d.readVarU32(&initialSizePages))
        return Fail(cx, d, "expected initial memory size");

    CheckedInt<int32_t> initialSize = initialSizePages;
    initialSize *= PageSize;
    if (!initialSize.isValid())
        return Fail(cx, d, "initial memory size too big");

    uint32_t maxSizePages;
    if (!d.readVarU32(&maxSizePages))
        return Fail(cx, d, "expected initial memory size");

    CheckedInt<int32_t> maxSize = maxSizePages;
    maxSize *= PageSize;
    if (!maxSize.isValid())
        return Fail(cx, d, "initial memory size too big");

    uint8_t exported;
    if (!d.readFixedU8(&exported))
        return Fail(cx, d, "expected exported byte");

    if (exported) {
        UniqueChars fieldName = DuplicateString("memory");
        if (!fieldName || !mg.addMemoryExport(Move(fieldName)))
            return false;
    }

    if (!d.finishSection(sectionStart))
        return Fail(cx, d, "memory section byte size mismatch");

    bool signalsForOOB = CompileArgs(cx).useSignalHandlersForOOB;
    heap.set(ArrayBufferObject::createForWasm(cx, initialSize.value(), signalsForOOB));
    if (!heap)
        return false;

    mg.initHeapUsage(HeapUsage::Unshared);
    return true;
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:48,代码来源:Wasm.cpp

示例10: DecodeFunctionExport

static bool
DecodeFunctionExport(JSContext* cx, Decoder& d, ModuleGenerator& mg, CStringSet* dupSet)
{
    uint32_t funcIndex;
    if (!d.readVarU32(&funcIndex))
        return Fail(cx, d, "expected export internal index");

    if (funcIndex >= mg.numFuncSigs())
        return Fail(cx, d, "export function index out of range");

    UniqueChars fieldName = DecodeFieldName(cx, d, dupSet);
    if (!fieldName)
        return false;

    return mg.declareExport(Move(fieldName), funcIndex);
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:16,代码来源:Wasm.cpp

示例11: DecodeFunc

static bool
DecodeFunc(JSContext* cx, Decoder& d, ModuleGenerator& mg, uint32_t funcIndex)
{
    int64_t before = PRMJ_Now();

    FunctionGenerator fg;
    if (!mg.startFuncDef(d.currentOffset(), &fg))
        return false;

    if (!d.readCStringIf(FuncSubsection))
        return Fail(cx, d, "expected 'func' tag");

    uint32_t sectionStart;
    if (!d.startSection(&sectionStart))
        return Fail(cx, d, "expected func section byte size");

    const DeclaredSig& sig = mg.funcSig(funcIndex);
    for (ValType type : sig.args()) {
        if (!fg.addLocal(type))
            return false;
    }

    uint32_t numVars;
    if (!d.readVarU32(&numVars))
        return Fail(cx, d, "expected number of local vars");

    for (uint32_t i = 0; i < numVars; i++) {
        ValType type;
        if (!DecodeValType(cx, d, &type))
            return false;
        if (!fg.addLocal(type))
            return false;
    }

    if (!DecodeFuncBody(cx, d, mg, fg, funcIndex))
        return false;

    if (!d.finishSection(sectionStart))
        return Fail(cx, d, "func section byte size mismatch");

    int64_t after = PRMJ_Now();
    unsigned generateTime = (after - before) / PRMJ_USEC_PER_MSEC;

    return mg.finishFuncDef(funcIndex, generateTime, &fg);
}
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:45,代码来源:Wasm.cpp

示例12: GenerateSyncInterruptStub

// Generate a stub that is called from the synchronous, inline interrupt checks
// when the interrupt flag is set. This stub calls the C++ function to handle
// the interrupt which returns whether execution has been interrupted.
static bool
GenerateSyncInterruptStub(ModuleGenerator& mg, Label* throwLabel)
{
    MacroAssembler& masm = mg.masm();

    masm.setFramePushed(0);
    unsigned framePushed = StackDecrementForCall(masm, ABIStackAlignment, ShadowStackSpace);

    ProfilingOffsets offsets;
    GenerateExitPrologue(masm, framePushed, ExitReason::Native, &offsets,
                         masm.asmSyncInterruptLabel());

    AssertStackAlignment(masm, ABIStackAlignment);
    masm.call(SymbolicAddress::HandleExecutionInterrupt);
    masm.branchIfFalseBool(ReturnReg, throwLabel);

    GenerateExitEpilogue(masm, framePushed, ExitReason::Native, &offsets);

    if (masm.oom())
        return false;

    offsets.end = masm.currentOffset();
    return mg.defineSyncInterruptStub(offsets);
}
开发者ID:tungmangtdh3,项目名称:gecko-dev,代码行数:27,代码来源:WasmStubs.cpp

示例13: DecodeCodeSection

static bool
DecodeCodeSection(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t funcIndex = 0;
    while (d.readCStringIf(CodeSection)) {
        uint32_t sectionStart;
        if (!d.startSection(&sectionStart))
            return Fail(cx, d, "expected code section byte size");

        uint32_t numFuncs;
        if (!d.readVarU32(&numFuncs))
            return Fail(cx, d, "expected number of functions");

        if (funcIndex + numFuncs > mg.numFuncSigs())
            return Fail(cx, d, "more function definitions than declarations");

        for (uint32_t i = 0; i < numFuncs; i++) {
            if (!DecodeFunc(cx, d, mg, funcIndex++))
                return false;
        }

        if (!d.finishSection(sectionStart))
            return Fail(cx, d, "code section byte size mismatch");
    }

    if (funcIndex != mg.numFuncSigs())
        return Fail(cx, d, "fewer function definitions than declarations");

    if (!mg.finishFuncDefs())
        return false;

    return true;
}
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:36,代码来源:Wasm.cpp

示例14: DecodeFunctionSections

static bool
DecodeFunctionSections(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t funcIndex = 0;

    for (; d.readCStringIf(FuncLabel); funcIndex++) {
        if (funcIndex >= mg.numFuncSigs())
            return Fail(cx, d, "more function definitions than declarations");

        if (!DecodeFunctionSection(cx, d, mg, funcIndex))
            return false;
    }

    if (funcIndex < mg.numFuncSigs())
        return Fail(cx, d, "fewer function definitions than declarations");

    if (!mg.finishFuncDefs())
        return false;

    return true;
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:24,代码来源:Wasm.cpp

示例15:

bool
wasm::GenerateStubs(ModuleGenerator& mg, bool usesHeap)
{
    for (unsigned i = 0; i < mg.numExports(); i++) {
        if (!GenerateEntry(mg, i, usesHeap))
            return false;
    }

    Label onThrow;

    for (size_t i = 0; i < mg.numImports(); i++) {
        ProfilingOffsets interp;
        if (!GenerateInterpExitStub(mg, i, &onThrow, &interp))
            return false;

        ProfilingOffsets jit;
        if (!GenerateJitExitStub(mg, i, usesHeap, &onThrow, &jit))
            return false;

        if (!mg.defineImport(i, interp, jit))
            return false;
    }

    if (mg.masm().asmStackOverflowLabel()->used()) {
        if (!GenerateStackOverflowStub(mg, &onThrow))
            return false;
    }

    if (mg.masm().asmSyncInterruptLabel()->used()) {
        if (!GenerateSyncInterruptStub(mg, &onThrow))
            return false;
    }

    if (mg.masm().asmOnConversionErrorLabel()->used()) {
        if (!GenerateConversionErrorStub(mg, &onThrow))
            return false;
    }

    // Generate unconditionally: the out-of-bounds exit may be used later even
    // if signal handling isn't used for out-of-bounds at the moment.
    if (!GenerateOutOfBoundsStub(mg, &onThrow))
        return false;

    // Generate unconditionally: the async interrupt may be taken at any time.
    if (!GenerateAsyncInterruptStub(mg, &onThrow))
        return false;

    if (onThrow.used()) {
        if (!GenerateThrowStub(mg, &onThrow))
            return false;
    }

    return true;
}
开发者ID:tungmangtdh3,项目名称:gecko-dev,代码行数:54,代码来源:WasmStubs.cpp


注:本文中的ModuleGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。