From 78e4332a8b783330887a15dc1416595f47564670 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 14 Jun 2016 10:39:02 +1000 Subject: [PATCH] move eod iter program into general eod program --- src/rose/program_runtime.h | 38 -------------------------------- src/rose/rose_build_bytecode.cpp | 36 ++++++++++++++---------------- src/rose/rose_dump.cpp | 11 +-------- src/rose/rose_internal.h | 3 +-- 4 files changed, 18 insertions(+), 70 deletions(-) diff --git a/src/rose/program_runtime.h b/src/rose/program_runtime.h index 5d255cf1..e23a395c 100644 --- a/src/rose/program_runtime.h +++ b/src/rose/program_runtime.h @@ -46,13 +46,6 @@ #include "util/fatbit.h" #include "util/multibit.h" -static rose_inline -hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, - struct hs_scratch *scratch, u32 programOffset, - u64a som, u64a end, size_t match_len, - char in_anchored, char in_catchup, char from_mpv, - char skip_mpv_catchup); - static rose_inline int roseCheckBenefits(const struct core_info *ci, u64a end, u32 mask_rewind, const u8 *and_mask, const u8 *exp_mask) { @@ -901,30 +894,6 @@ hwlmcb_rv_t roseSuffixesEod(const struct RoseEngine *rose, } static rose_inline -int roseEodRunIterator(const struct RoseEngine *t, u64a offset, - struct hs_scratch *scratch) { - if (!t->eodIterProgramOffset) { - return MO_CONTINUE_MATCHING; - } - - DEBUG_PRINTF("running eod program at offset %u\n", t->eodIterProgramOffset); - - const u64a som = 0; - const size_t match_len = 0; - const char in_anchored = 0; - const char in_catchup = 0; - const char from_mpv = 0; - const char skip_mpv_catchup = 1; - if (roseRunProgram(t, scratch, t->eodIterProgramOffset, som, offset, - match_len, in_anchored, in_catchup, - from_mpv, skip_mpv_catchup) == HWLM_TERMINATE_MATCHING) { - return MO_HALT_MATCHING; - } - - return MO_CONTINUE_MATCHING; -} - -static hwlmcb_rv_t roseMatcherEod(const struct RoseEngine *rose, struct hs_scratch *scratch, u64a offset) { assert(rose->ematcherOffset); @@ -977,13 +946,6 @@ hwlmcb_rv_t roseMatcherEod(const struct RoseEngine *rose, } roseFlushLastByteHistory(rose, scratch, offset); - - // Fire any new EOD reports. - if (roseEodRunIterator(rose, offset, scratch) == MO_HALT_MATCHING) { - DEBUG_PRINTF("user instructed us to stop\n"); - return HWLM_TERMINATE_MATCHING; - } - return HWLM_CONTINUE_MATCHING; } diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index c472337d..32150b79 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -4015,11 +4015,9 @@ bool hasEodMatcher(const RoseBuildImpl &build) { return false; } -/** - * Returns the pair (program offset, sparse iter offset). - */ static -u32 writeEodAnchorProgram(RoseBuildImpl &build, build_context &bc) { +void addEodAnchorProgram(RoseBuildImpl &build, build_context &bc, + vector &program) { const RoseGraph &g = build.g; // pred state id -> list of programs @@ -4058,10 +4056,7 @@ u32 writeEodAnchorProgram(RoseBuildImpl &build, build_context &bc) { } } - vector program; - if (!predProgramLists.empty()) { - addPredBlocks(bc, predProgramLists, program); - } + addPredBlocks(bc, predProgramLists, program); if (hasEodAnchoredSuffix(build)) { if (!program.empty()) { @@ -4069,17 +4064,8 @@ u32 writeEodAnchorProgram(RoseBuildImpl &build, build_context &bc) { program.pop_back(); } program.emplace_back(ROSE_INSTR_SUFFIXES_EOD); + program.emplace_back(ROSE_INSTR_END); } - - if (program.empty()) { - return 0; - } - - program = flattenProgram({program}); - - assert(program.size() > 1); - applyFinalSpecialisation(program); - return writeProgram(bc, program); } static @@ -4139,6 +4125,11 @@ void addGeneralEodAnchorProgram(RoseBuildImpl &build, build_context &bc, program.emplace_back(ROSE_INSTR_MATCHER_EOD); program.emplace_back(ROSE_INSTR_END); } + + if (!program.empty()) { + assert(program.back().code() == ROSE_INSTR_END); + program.pop_back(); + } } static @@ -4184,11 +4175,18 @@ u32 writeEodProgram(RoseBuildImpl &build, build_context &bc, } addGeneralEodAnchorProgram(build, bc, program); + addEodAnchorProgram(build, bc, program); + + if (program.size() == 1) { + assert(program.back().code() == ROSE_INSTR_END); + return 0; + } if (program.empty()) { return 0; } + applyFinalSpecialisation(program); return writeProgram(bc, program); } @@ -4355,7 +4353,6 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { buildLiteralPrograms(*this, bc); u32 eodProgramOffset = writeEodProgram(*this, bc, eodNfaIterOffset); - u32 eodIterProgramOffset = writeEodAnchorProgram(*this, bc); vector activeLeftIter; buildActiveLeftIter(leftInfoTable, activeLeftIter); @@ -4552,7 +4549,6 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { engine->nfaInfoOffset = nfaInfoOffset; engine->eodProgramOffset = eodProgramOffset; - engine->eodIterProgramOffset = eodIterProgramOffset; engine->lastByteHistoryIterOffset = lastByteOffset; diff --git a/src/rose/rose_dump.cpp b/src/rose/rose_dump.cpp index 5bcff4fc..40979e8c 100644 --- a/src/rose/rose_dump.cpp +++ b/src/rose/rose_dump.cpp @@ -542,7 +542,7 @@ void dumpRoseEodPrograms(const RoseEngine *t, const string &filename) { ofstream os(filename); const char *base = (const char *)t; - os << "Unconditional EOD Program:" << endl; + os << "EOD Program:" << endl; if (t->eodProgramOffset) { dumpProgram(os, t, base + t->eodProgramOffset); @@ -551,14 +551,6 @@ void dumpRoseEodPrograms(const RoseEngine *t, const string &filename) { os << "" << endl; } - os << "Sparse Iter EOD Program:" << endl; - - if (t->eodIterProgramOffset) { - dumpProgram(os, t, base + t->eodIterProgramOffset); - } else { - os << "" << endl; - } - os.close(); } @@ -1031,7 +1023,6 @@ void roseDumpStructRaw(const RoseEngine *t, FILE *f) { DUMP_U32(t, lookaroundTableOffset); DUMP_U32(t, lookaroundReachOffset); DUMP_U32(t, eodProgramOffset); - DUMP_U32(t, eodIterProgramOffset); DUMP_U32(t, lastByteHistoryIterOffset); DUMP_U32(t, minWidth); DUMP_U32(t, minWidthExcludingBoundaries); diff --git a/src/rose/rose_internal.h b/src/rose/rose_internal.h index faab45f7..366636b6 100644 --- a/src/rose/rose_internal.h +++ b/src/rose/rose_internal.h @@ -376,8 +376,7 @@ struct RoseEngine { u32 lookaroundReachOffset; /**< base of lookaround reach bitvectors (32 * bytes each) */ - u32 eodProgramOffset; //!< Unconditional EOD program, otherwise 0. - u32 eodIterProgramOffset; // or 0 if no eod iterator program + u32 eodProgramOffset; //!< EOD program, otherwise 0. u32 lastByteHistoryIterOffset; // if non-zero