本文整理汇总了C++中ModuleGenerator::startFuncDef方法的典型用法代码示例。如果您正苦于以下问题:C++ ModuleGenerator::startFuncDef方法的具体用法?C++ ModuleGenerator::startFuncDef怎么用?C++ ModuleGenerator::startFuncDef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleGenerator
的用法示例。
在下文中一共展示了ModuleGenerator::startFuncDef方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Fail
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);
}
示例2: Fail
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(§ionStart))
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);
}