mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
rose: move lookaround tables to engine blob
This commit is contained in:
parent
b6254ca11f
commit
e3d2d67833
@ -2683,13 +2683,15 @@ bool hasEodAnchors(const RoseBuildImpl &build, const build_context &bc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void fillLookaroundTables(char *look_base, char *reach_base,
|
void writeLookaroundTables(build_context &bc, RoseEngine &proto) {
|
||||||
const vector<LookEntry> &look_vec) {
|
const auto &look_vec = bc.lookaround;
|
||||||
DEBUG_PRINTF("%zu lookaround table entries\n", look_vec.size());
|
DEBUG_PRINTF("%zu lookaround table entries\n", look_vec.size());
|
||||||
|
|
||||||
s8 *look = (s8 *)look_base;
|
vector<s8> look_table(look_vec.size(), 0);
|
||||||
u8 *reach = (u8 *)reach_base; // base for 256-bit bitvectors
|
vector<u8> reach_table(REACH_BITVECTOR_LEN * look_vec.size(), 0);
|
||||||
|
|
||||||
|
s8 *look = look_table.data();
|
||||||
|
u8 *reach = reach_table.data();
|
||||||
for (const auto &le : look_vec) {
|
for (const auto &le : look_vec) {
|
||||||
*look = verify_s8(le.offset);
|
*look = verify_s8(le.offset);
|
||||||
const CharReach &cr = le.reach;
|
const CharReach &cr = le.reach;
|
||||||
@ -2700,6 +2702,11 @@ void fillLookaroundTables(char *look_base, char *reach_base,
|
|||||||
++look;
|
++look;
|
||||||
reach += REACH_BITVECTOR_LEN;
|
reach += REACH_BITVECTOR_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proto.lookaroundTableOffset =
|
||||||
|
bc.engine_blob.add(begin(look_table), end(look_table));
|
||||||
|
proto.lookaroundReachOffset =
|
||||||
|
bc.engine_blob.add(begin(reach_table), end(reach_table));
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -5376,6 +5383,8 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
|
|
||||||
addSomRevNfas(bc, proto, ssm);
|
addSomRevNfas(bc, proto, ssm);
|
||||||
|
|
||||||
|
writeLookaroundTables(bc, proto);
|
||||||
|
|
||||||
// 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();
|
||||||
@ -5446,12 +5455,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
proto.leftOffset = currOffset;
|
proto.leftOffset = currOffset;
|
||||||
currOffset += sizeof(LeftNfaInfo) * leftInfoTable.size();
|
currOffset += sizeof(LeftNfaInfo) * leftInfoTable.size();
|
||||||
|
|
||||||
proto.lookaroundReachOffset = currOffset;
|
|
||||||
currOffset += REACH_BITVECTOR_LEN * bc.lookaround.size();
|
|
||||||
|
|
||||||
proto.lookaroundTableOffset = currOffset;
|
|
||||||
currOffset += sizeof(s8) * bc.lookaround.size();
|
|
||||||
|
|
||||||
currOffset = ROUNDUP_N(currOffset, sizeof(u32));
|
currOffset = ROUNDUP_N(currOffset, sizeof(u32));
|
||||||
proto.nfaInfoOffset = currOffset;
|
proto.nfaInfoOffset = currOffset;
|
||||||
currOffset += sizeof(NfaInfo) * queue_count;
|
currOffset += sizeof(NfaInfo) * queue_count;
|
||||||
@ -5597,9 +5600,6 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
|
|||||||
bc.engine_blob.write_bytes(engine.get());
|
bc.engine_blob.write_bytes(engine.get());
|
||||||
copy_bytes(ptr + engine->leftOffset, leftInfoTable);
|
copy_bytes(ptr + engine->leftOffset, leftInfoTable);
|
||||||
|
|
||||||
fillLookaroundTables(ptr + proto.lookaroundTableOffset,
|
|
||||||
ptr + proto.lookaroundReachOffset, bc.lookaround);
|
|
||||||
|
|
||||||
// Safety check: we shouldn't have written anything to the engine blob
|
// Safety check: we shouldn't have written anything to the engine blob
|
||||||
// after we copied it into the engine bytecode.
|
// after we copied it into the engine bytecode.
|
||||||
assert(bc.engine_blob.size() == engineBlobSize);
|
assert(bc.engine_blob.size() == engineBlobSize);
|
||||||
|
@ -1694,10 +1694,6 @@ void roseDumpText(const RoseEngine *t, FILE *f) {
|
|||||||
t->rolesWithStateCount * sizeof(u32));
|
t->rolesWithStateCount * sizeof(u32));
|
||||||
fprintf(f, " - nfa info table : %zu bytes\n",
|
fprintf(f, " - nfa info table : %zu bytes\n",
|
||||||
t->queueCount * sizeof(NfaInfo));
|
t->queueCount * sizeof(NfaInfo));
|
||||||
fprintf(f, " - lookaround table : %u bytes\n",
|
|
||||||
t->nfaInfoOffset - t->lookaroundTableOffset);
|
|
||||||
fprintf(f, " - lookaround reach : %u bytes\n",
|
|
||||||
t->lookaroundTableOffset - t->lookaroundReachOffset);
|
|
||||||
|
|
||||||
fprintf(f, "state space required : %u bytes\n", t->stateOffsets.end);
|
fprintf(f, "state space required : %u bytes\n", t->stateOffsets.end);
|
||||||
fprintf(f, " - history buffer : %u bytes\n", t->historyRequired);
|
fprintf(f, " - history buffer : %u bytes\n", t->historyRequired);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user