From e3d2d678330b4954b126d8b3d88087b1eb52ac49 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 28 Feb 2017 11:18:23 +1100 Subject: [PATCH] rose: move lookaround tables to engine blob --- src/rose/rose_build_bytecode.cpp | 26 +++++++++++++------------- src/rose/rose_build_dump.cpp | 4 ---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index 12b51757..05e46ca8 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -2683,13 +2683,15 @@ bool hasEodAnchors(const RoseBuildImpl &build, const build_context &bc, } static -void fillLookaroundTables(char *look_base, char *reach_base, - const vector &look_vec) { +void writeLookaroundTables(build_context &bc, RoseEngine &proto) { + const auto &look_vec = bc.lookaround; DEBUG_PRINTF("%zu lookaround table entries\n", look_vec.size()); - s8 *look = (s8 *)look_base; - u8 *reach = (u8 *)reach_base; // base for 256-bit bitvectors + vector look_table(look_vec.size(), 0); + vector 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) { *look = verify_s8(le.offset); const CharReach &cr = le.reach; @@ -2700,6 +2702,11 @@ void fillLookaroundTables(char *look_base, char *reach_base, ++look; 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 @@ -5376,6 +5383,8 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { addSomRevNfas(bc, proto, ssm); + writeLookaroundTables(bc, proto); + // Enforce role table resource limit. if (num_vertices(g) > cc.grey.limitRoseRoleCount) { throw ResourceLimitError(); @@ -5446,12 +5455,6 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { proto.leftOffset = currOffset; 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)); proto.nfaInfoOffset = currOffset; currOffset += sizeof(NfaInfo) * queue_count; @@ -5597,9 +5600,6 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { bc.engine_blob.write_bytes(engine.get()); 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 // after we copied it into the engine bytecode. assert(bc.engine_blob.size() == engineBlobSize); diff --git a/src/rose/rose_build_dump.cpp b/src/rose/rose_build_dump.cpp index 2f882e68..a13fc964 100644 --- a/src/rose/rose_build_dump.cpp +++ b/src/rose/rose_build_dump.cpp @@ -1694,10 +1694,6 @@ void roseDumpText(const RoseEngine *t, FILE *f) { t->rolesWithStateCount * sizeof(u32)); fprintf(f, " - nfa info table : %zu bytes\n", 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, " - history buffer : %u bytes\n", t->historyRequired);