本文整理汇总了C++中FuncEmitter类的典型用法代码示例。如果您正苦于以下问题:C++ FuncEmitter类的具体用法?C++ FuncEmitter怎么用?C++ FuncEmitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FuncEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assertx
void UnitEmitter::initMain(int line1, int line2) {
assertx(m_fes.size() == 0);
StringData* name = staticEmptyString();
FuncEmitter* pseudomain = newFuncEmitter(name);
Attr attrs = AttrMayUseVV;
pseudomain->init(line1, line2, 0, attrs, false, name);
}
示例2: build_exn_tree
ExnTreeInfo build_exn_tree(const FuncEmitter& fe,
php::Func& func,
FindBlock findBlock) {
ExnTreeInfo ret;
uint32_t nextExnNode = 0;
for (auto& eh : fe.ehtab()) {
auto node = folly::make_unique<php::ExnNode>();
node->id = nextExnNode++;
node->parent = nullptr;
switch (eh.m_type) {
case EHEnt::Type::Fault:
{
auto const fault = findBlock(eh.m_fault);
assert(ret.funcletNodes[fault] == nullptr);
ret.funcletNodes[fault] = borrow(node);
/*
* We know the block for this offset starts a fault funclet,
* but we won't know its extents until we've built the cfg and
* can look at the control flow in the funclet. Set the block
* type to Fault for now, but we won't propagate the value to
* the rest of the funclet blocks until find_fault_funclets.
*/
fault->kind = php::Block::Kind::Fault;
node->info = php::FaultRegion { fault, eh.m_iterId, eh.m_itRef };
}
break;
case EHEnt::Type::Catch:
{
auto treg = php::TryRegion {};
for (auto& centry : eh.m_catches) {
auto const catchBlk = findBlock(centry.second);
catchBlk->kind = php::Block::Kind::CatchEntry;
treg.catches.emplace_back(
fe.ue().lookupLitstr(centry.first),
catchBlk
);
}
node->info = treg;
}
break;
}
ret.ehMap[&eh] = borrow(node);
if (eh.m_parentIndex != -1) {
auto it = ret.ehMap.find(&fe.ehtab()[eh.m_parentIndex]);
assert(it != end(ret.ehMap));
node->parent = it->second;
it->second->children.emplace_back(std::move(node));
} else {
func.exnNodes.emplace_back(std::move(node));
}
}
return ret;
}
示例3: add_frame_variables
void add_frame_variables(php::Func& func, const FuncEmitter& fe) {
for (auto& param : fe.params) {
func.params.push_back(
php::Param {
param.defaultValue,
NoBlockId,
param.typeConstraint,
param.userType,
param.phpCode,
param.userAttributes,
param.builtinType,
param.byRef,
param.byRef,
param.variadic
}
);
}
func.locals.reserve(fe.numLocals());
for (LocalId id = 0; id < fe.numLocals(); ++id) {
func.locals.push_back({nullptr, id, false});
}
for (auto& kv : fe.localNameMap()) {
func.locals[kv.second].name = kv.first;
}
func.numIters = fe.numIterators();
func.staticLocals.reserve(fe.staticVars.size());
for (auto& sv : fe.staticVars) {
func.staticLocals.push_back(
php::StaticLocalInfo { sv.name, sv.phpCode }
);
}
}
示例4: ASSERT
void UnitEmitter::initMain(int line1, int line2) {
ASSERT(m_fes.size() == 0);
StringData* name = StringData::GetStaticString("");
FuncEmitter* pseudomain = newFuncEmitter(name, false);
Attr attrs = AttrMayUseVV;
pseudomain->init(line1, line2, 0, attrs, false, name);
}
示例5: emit_init_func
void emit_init_func(FuncEmitter& fe, const php::Func& func) {
fe.init(
std::get<0>(func.srcInfo.loc),
std::get<1>(func.srcInfo.loc),
fe.ue().bcPos(),
func.attrs,
func.top,
func.srcInfo.docComment
);
}
示例6: build_cfg
void build_cfg(ParseUnitState& puState,
php::Func& func,
const FuncEmitter& fe) {
auto const blockStarts = findBasicBlocks(fe);
FTRACE(3, " blocks are at: {}\n",
[&]() -> std::string {
using namespace folly::gen;
return from(blockStarts)
| eachTo<std::string>()
| unsplit<std::string>(" ");
}()
);
std::map<Offset,std::unique_ptr<php::Block>> blockMap;
auto const bc = fe.ue().bc();
auto findBlock = [&] (Offset off) {
auto& ptr = blockMap[off];
if (!ptr) {
ptr = folly::make_unique<php::Block>();
ptr->id = func.nextBlockId++;
ptr->section = php::Block::Section::Main;
ptr->exnNode = nullptr;
}
return borrow(ptr);
};
auto exnTreeInfo = build_exn_tree(fe, func, findBlock);
for (auto it = begin(blockStarts);
boost::next(it) != end(blockStarts);
++it) {
auto const block = findBlock(*it);
auto const bcStart = bc + *it;
auto const bcStop = bc + *boost::next(it);
if (auto const eh = findEH(fe.ehtab(), *it)) {
auto it = exnTreeInfo.ehMap.find(eh);
assert(it != end(exnTreeInfo.ehMap));
block->exnNode = it->second;
add_factored_exits(*block, block->exnNode);
}
populate_block(puState, fe, func, *block, bcStart, bcStop, findBlock);
}
link_entry_points(func, fe, findBlock);
find_fault_funclets(exnTreeInfo, func, blockStarts, findBlock);
for (auto& kv : blockMap) {
func.blocks.emplace_back(std::move(kv.second));
}
}
示例7: link_entry_points
void link_entry_points(php::Func& func,
const FuncEmitter& fe,
FindBlk findBlock) {
func.dvEntries.resize(fe.params().size());
for (size_t i = 0, sz = fe.params().size(); i < sz; ++i) {
if (fe.params()[i].hasDefaultValue()) {
auto const dv = findBlock(fe.params()[i].funcletOff());
func.params[i].dvEntryPoint = dv;
func.dvEntries[i] = dv;
}
}
func.mainEntry = findBlock(fe.base());
}
示例8: build_exn_tree
ExnTreeInfo build_exn_tree(const FuncEmitter& fe,
php::Func& func,
FindBlock findBlock) {
ExnTreeInfo ret;
auto nextExnNode = uint32_t{0};
for (auto& eh : fe.ehtab()) {
auto node = folly::make_unique<php::ExnNode>();
node->id = nextExnNode++;
node->parent = nullptr;
switch (eh.m_type) {
case EHEnt::Type::Fault:
{
auto const fault = findBlock(eh.m_fault);
ret.funcletNodes[fault].push_back(borrow(node));
ret.faultFuncletStarts.insert(eh.m_fault);
node->info = php::FaultRegion { fault, eh.m_iterId, eh.m_itRef };
}
break;
case EHEnt::Type::Catch:
{
auto treg = php::TryRegion {};
for (auto& centry : eh.m_catches) {
auto const catchBlk = findBlock(centry.second);
treg.catches.emplace_back(
fe.ue().lookupLitstr(centry.first),
catchBlk
);
}
node->info = treg;
}
break;
}
ret.ehMap[&eh] = borrow(node);
if (eh.m_parentIndex != -1) {
auto it = ret.ehMap.find(&fe.ehtab()[eh.m_parentIndex]);
assert(it != end(ret.ehMap));
node->parent = it->second;
it->second->children.emplace_back(std::move(node));
} else {
func.exnNodes.emplace_back(std::move(node));
}
}
ret.faultFuncletStarts.insert(fe.past());
return ret;
}
示例9: createFatalUnit
std::unique_ptr<UnitEmitter>
createFatalUnit(StringData* filename, const MD5& md5, FatalOp /*op*/,
StringData* err) {
auto ue = std::make_unique<UnitEmitter>(md5);
ue->m_filepath = filename;
ue->initMain(1, 1);
ue->emitOp(OpString);
ue->emitInt32(ue->mergeLitstr(err));
ue->emitOp(OpFatal);
ue->emitByte(static_cast<uint8_t>(FatalOp::Runtime));
FuncEmitter* fe = ue->getMain();
fe->maxStackCells = 1;
// XXX line numbers are bogus
fe->finish(ue->bcPos(), false);
ue->recordFunction(fe);
return ue;
}
示例10: emit_eh_region
void emit_eh_region(FuncEmitter& fe,
borrowed_ptr<const EHRegion> region,
const BlockInfo& blockInfo,
ParentIndexMap& parentIndexMap) {
// A region on a single empty block.
if (region->start == region->past) return;
auto& eh = fe.addEHEnt();
eh.m_base = region->start;
eh.m_past = region->past;
assert(eh.m_past >= eh.m_base);
assert(eh.m_base != kInvalidOffset && eh.m_past != kInvalidOffset);
if (region->parent) {
auto parentIt = parentIndexMap.find(region->parent);
assert(parentIt != end(parentIndexMap));
eh.m_parentIndex = parentIt->second;
} else {
eh.m_parentIndex = -1;
}
parentIndexMap[region] = fe.ehtab.size() - 1;
match<void>(
region->node->info,
[&] (const php::TryRegion& tr) {
eh.m_type = EHEnt::Type::Catch;
for (auto& c : tr.catches) {
eh.m_catches.emplace_back(
fe.ue().mergeLitstr(c.first),
blockInfo[c.second->id].offset
);
}
eh.m_fault = kInvalidOffset;
eh.m_iterId = -1;
eh.m_itRef = false;
},
[&] (const php::FaultRegion& fr) {
eh.m_type = EHEnt::Type::Fault;
eh.m_fault = blockInfo[fr.faultEntry->id].offset;
eh.m_iterId = fr.iterId;
eh.m_itRef = fr.itRef;
}
);
}
示例11: add_frame_variables
void add_frame_variables(php::Func& func, const FuncEmitter& fe) {
for (auto& param : fe.params) {
func.params.push_back(
php::Param {
param.defaultValue,
nullptr,
param.typeConstraint,
param.userType,
param.phpCode,
param.userAttributes,
param.builtinType,
param.byRef,
param.variadic
}
);
}
func.locals.resize(fe.numLocals());
for (size_t id = 0; id < func.locals.size(); ++id) {
auto& loc = func.locals[id];
loc = folly::make_unique<php::Local>();
loc->id = id;
loc->name = nullptr;
}
for (auto& kv : fe.localNameMap()) {
func.locals[kv.second]->name = kv.first;
}
func.iters.resize(fe.numIterators());
for (uint32_t i = 0; i < func.iters.size(); ++i) {
func.iters[i] = folly::make_unique<php::Iter>();
func.iters[i]->id = i;
}
func.staticLocals.reserve(fe.staticVars.size());
for (auto& sv : fe.staticVars) {
func.staticLocals.push_back(
php::StaticLocalInfo { sv.name, sv.phpCode }
);
}
}
示例12: emit_finish_func
void emit_finish_func(const php::Func& func,
FuncEmitter& fe,
const EmitBcInfo& info) {
if (info.containsCalls) fe.containsCalls = true;;
for (auto& fpi : info.fpiRegions) {
auto& e = fe.addFPIEnt();
e.m_fpushOff = fpi.fpushOff;
e.m_fcallOff = fpi.fcallOff;
e.m_fpOff = fpi.fpDelta;
}
emit_locals_and_params(fe, func, info);
emit_ehent_tree(fe, func, info);
fe.userAttributes = func.userAttributes;
fe.retUserType = func.returnUserType;
fe.originalFilename = func.originalFilename;
fe.isClosureBody = func.isClosureBody;
fe.isAsync = func.isAsync;
fe.isGenerator = func.isGenerator;
fe.isPairGenerator = func.isPairGenerator;
if (func.nativeInfo) {
fe.returnType = func.nativeInfo->returnType;
}
fe.retTypeConstraint = func.retTypeConstraint;
fe.maxStackCells = info.maxStackDepth +
fe.numLocals() +
fe.numIterators() * kNumIterCells +
info.maxFpiDepth * kNumActRecCells;
fe.finish(fe.ue().bcPos(), false /* load */);
fe.ue().recordFunction(&fe);
}
示例13: parse_func
std::unique_ptr<php::Func> parse_func(ParseUnitState& puState,
borrowed_ptr<php::Unit> unit,
borrowed_ptr<php::Class> cls,
const FuncEmitter& fe) {
FTRACE(2, " func: {}\n",
fe.name->data() && *fe.name->data() ? fe.name->data() : "pseudomain");
auto ret = folly::make_unique<php::Func>();
ret->name = fe.name;
ret->srcInfo = php::SrcInfo { fe.getLocation(),
fe.docComment };
ret->unit = unit;
ret->cls = cls;
ret->nextBlockId = 0;
ret->attrs = static_cast<Attr>(fe.attrs & ~AttrNoOverride);
ret->userAttributes = fe.userAttributes;
ret->returnUserType = fe.retUserType;
ret->retTypeConstraint = fe.retTypeConstraint;
ret->originalFilename = fe.originalFilename;
ret->top = fe.top;
ret->isClosureBody = fe.isClosureBody;
ret->isAsync = fe.isAsync;
ret->isGenerator = fe.isGenerator;
ret->isPairGenerator = fe.isPairGenerator;
ret->isNative = fe.isNative;
/*
* Builtin functions get some extra information. The returnType flag is only
* non-folly::none for these, but note that something may be a builtin and
* still have a folly::none return type.
*/
if (fe.attrs & AttrBuiltin) {
ret->nativeInfo = folly::make_unique<php::NativeInfo>();
ret->nativeInfo->returnType = fe.returnType;
}
add_frame_variables(*ret, fe);
build_cfg(puState, *ret, fe);
return ret;
}
示例14: txn
void FuncRepoProxy::GetFuncsStmt
::get(UnitEmitter& ue) {
RepoTxn txn(m_repo);
if (!prepared()) {
std::stringstream ssSelect;
ssSelect << "SELECT funcSn,preClassId,name,top,extraData "
"FROM "
<< m_repo.table(m_repoId, "Func")
<< " WHERE unitSn == @unitSn ORDER BY funcSn ASC;";
txn.prepare(*this, ssSelect.str());
}
RepoTxnQuery query(txn, *this);
query.bindInt64("@unitSn", ue.m_sn);
do {
query.step();
if (query.row()) {
int funcSn; /**/ query.getInt(0, funcSn);
Id preClassId; /**/ query.getId(1, preClassId);
StringData* name; /**/ query.getStaticString(2, name);
bool top; /**/ query.getBool(3, top);
BlobDecoder extraBlob = /**/ query.getBlob(4);
FuncEmitter* fe;
if (preClassId < 0) {
fe = ue.newFuncEmitter(name);
} else {
PreClassEmitter* pce = ue.pce(preClassId);
fe = ue.newMethodEmitter(name, pce);
bool added UNUSED = pce->addMethod(fe);
assert(added);
}
assert(fe->sn() == funcSn);
fe->top = top;
fe->serdeMetaData(extraBlob);
if (!SystemLib::s_inited && !fe->isPseudoMain()) {
assert(fe->attrs & AttrBuiltin);
if (preClassId < 0) {
assert(fe->attrs & AttrPersistent);
assert(fe->attrs & AttrUnique);
assert(fe->attrs & AttrSkipFrame);
}
}
fe->setEHTabIsSorted();
fe->finish(fe->past, true);
ue.recordFunction(fe);
}
} while (!query.done());
txn.commit();
}
示例15: emit_finish_func
void emit_finish_func(const php::Func& func,
FuncEmitter& fe,
const EmitBcInfo& info) {
fe.setMaxStackCells(
info.maxStackDepth + fe.numLocals() +
info.maxFpiDepth * kNumActRecCells
);
if (info.containsCalls) fe.setContainsCalls();
for (auto& fpi : info.fpiRegions) {
auto& e = fe.addFPIEnt();
e.m_fpushOff = fpi.fpushOff;
e.m_fcallOff = fpi.fcallOff;
e.m_fpOff = fpi.fpDelta;
}
emit_locals_and_params(fe, func, info);
emit_ehent_tree(fe, func, info);
fe.setUserAttributes(func.userAttributes);
fe.setReturnUserType(func.returnUserType);
fe.setOriginalFilename(func.originalFilename);
fe.setIsClosureBody(func.isClosureBody);
fe.setIsGenerator(func.isGeneratorBody);
fe.setIsGeneratorFromClosure(func.isGeneratorFromClosure);
fe.setIsPairGenerator(func.isPairGenerator);
fe.setGeneratorBodyName(func.generatorBodyName);
fe.setIsAsync(func.isAsync);
fe.finish(fe.ue().bcPos(), false /* load */);
fe.ue().recordFunction(&fe);
}