mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
rose: move SOM reverse NFAs to engine_blob
This commit is contained in:
parent
f4bda9def6
commit
282f72e04d
@ -2457,57 +2457,24 @@ struct DerivedBoundaryReports {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static
|
static
|
||||||
void prepSomRevNfas(const SomSlotManager &ssm, u32 *rev_nfa_table_offset,
|
void addSomRevNfas(build_context &bc, RoseEngine &proto,
|
||||||
vector<u32> *nfa_offsets, u32 *currOffset) {
|
const SomSlotManager &ssm) {
|
||||||
const deque<aligned_unique_ptr<NFA>> &nfas = ssm.getRevNfas();
|
const auto &nfas = ssm.getRevNfas();
|
||||||
|
vector<u32> nfa_offsets;
|
||||||
*currOffset = ROUNDUP_N(*currOffset, alignof(u32));
|
nfa_offsets.reserve(nfas.size());
|
||||||
*rev_nfa_table_offset = *currOffset;
|
for (const auto &nfa : nfas) {
|
||||||
*currOffset += sizeof(u32) * nfas.size();
|
assert(nfa);
|
||||||
|
u32 offset = bc.engine_blob.add(*nfa, nfa->length);
|
||||||
*currOffset = ROUNDUP_CL(*currOffset);
|
DEBUG_PRINTF("wrote SOM rev NFA %zu (len %u) to offset %u\n",
|
||||||
for (const auto &n : nfas) {
|
nfa_offsets.size(), nfa->length, offset);
|
||||||
u32 bs_offset;
|
nfa_offsets.push_back(offset);
|
||||||
bs_offset = *currOffset;
|
|
||||||
nfa_offsets->push_back(bs_offset);
|
|
||||||
*currOffset += ROUNDUP_CL(n->length);
|
|
||||||
/* note: som rev nfas don't need a queue assigned as only run in block
|
/* note: som rev nfas don't need a queue assigned as only run in block
|
||||||
* mode reverse */
|
* mode reverse */
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(nfa_offsets->size() == nfas.size());
|
proto.somRevCount = verify_u32(nfas.size());
|
||||||
}
|
proto.somRevOffsetOffset =
|
||||||
|
bc.engine_blob.add(begin(nfa_offsets), end(nfa_offsets));
|
||||||
static
|
|
||||||
void fillInSomRevNfas(RoseEngine *engine, const SomSlotManager &ssm,
|
|
||||||
u32 rev_nfa_table_offset,
|
|
||||||
const vector<u32> &nfa_offsets) {
|
|
||||||
const deque<aligned_unique_ptr<NFA>> &nfas = ssm.getRevNfas();
|
|
||||||
assert(nfa_offsets.size() == nfas.size());
|
|
||||||
|
|
||||||
engine->somRevCount = (u32)nfas.size();
|
|
||||||
engine->somRevOffsetOffset = rev_nfa_table_offset;
|
|
||||||
|
|
||||||
if (nfas.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *out = (char *)engine + rev_nfa_table_offset;
|
|
||||||
size_t table_size = sizeof(u32) * nfa_offsets.size();
|
|
||||||
memcpy(out, nfa_offsets.data(), table_size);
|
|
||||||
out = (char *)engine + ROUNDUP_CL(rev_nfa_table_offset + table_size);
|
|
||||||
|
|
||||||
// Write the SOM reverse NFAs into place.
|
|
||||||
UNUSED size_t i = 0;
|
|
||||||
for (const auto &n : nfas) {
|
|
||||||
assert(n != nullptr);
|
|
||||||
assert(out == (char *)engine + nfa_offsets[i]);
|
|
||||||
|
|
||||||
memcpy(out, n.get(), n->length);
|
|
||||||
out += ROUNDUP_CL(n->length);
|
|
||||||
DEBUG_PRINTF("wrote som rev nfa with len %u\n", n->length);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -5408,6 +5375,8 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
proto.eagerIterOffset = buildEagerQueueIter(
|
proto.eagerIterOffset = buildEagerQueueIter(
|
||||||
eager_queues, proto.leftfixBeginQueue, queue_count, bc);
|
eager_queues, proto.leftfixBeginQueue, queue_count, bc);
|
||||||
|
|
||||||
|
addSomRevNfas(bc, proto, ssm);
|
||||||
|
|
||||||
// Enforce role table resource limit.
|
// Enforce role table resource limit.
|
||||||
if (num_vertices(g) > cc.grey.limitRoseRoleCount) {
|
if (num_vertices(g) > cc.grey.limitRoseRoleCount) {
|
||||||
throw ResourceLimitError();
|
throw ResourceLimitError();
|
||||||
@ -5499,10 +5468,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
proto.activeLeftCount = verify_u32(leftInfoTable.size());
|
proto.activeLeftCount = verify_u32(leftInfoTable.size());
|
||||||
proto.rosePrefixCount = countRosePrefixes(leftInfoTable);
|
proto.rosePrefixCount = countRosePrefixes(leftInfoTable);
|
||||||
|
|
||||||
u32 rev_nfa_table_offset;
|
|
||||||
vector<u32> rev_nfa_offsets;
|
|
||||||
prepSomRevNfas(ssm, &rev_nfa_table_offset, &rev_nfa_offsets, &currOffset);
|
|
||||||
|
|
||||||
proto.anchorStateSize = atable ? anchoredStateSize(*atable) : 0;
|
proto.anchorStateSize = atable ? anchoredStateSize(*atable) : 0;
|
||||||
|
|
||||||
DEBUG_PRINTF("rose history required %zu\n", historyRequired);
|
DEBUG_PRINTF("rose history required %zu\n", historyRequired);
|
||||||
@ -5643,7 +5608,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
fillLookaroundTables(ptr + proto.lookaroundTableOffset,
|
fillLookaroundTables(ptr + proto.lookaroundTableOffset,
|
||||||
ptr + proto.lookaroundReachOffset, bc.lookaround);
|
ptr + proto.lookaroundReachOffset, bc.lookaround);
|
||||||
|
|
||||||
fillInSomRevNfas(engine.get(), ssm, rev_nfa_table_offset, rev_nfa_offsets);
|
|
||||||
copy_bytes(ptr + engine->activeLeftIterOffset, activeLeftIter);
|
copy_bytes(ptr + engine->activeLeftIterOffset, activeLeftIter);
|
||||||
|
|
||||||
// Safety check: we shouldn't have written anything to the engine blob
|
// Safety check: we shouldn't have written anything to the engine blob
|
||||||
|
Loading…
x
Reference in New Issue
Block a user