diff --git a/src/nfa/castlecompile.cpp b/src/nfa/castlecompile.cpp index b18eb9ad..7d37ef81 100644 --- a/src/nfa/castlecompile.cpp +++ b/src/nfa/castlecompile.cpp @@ -708,6 +708,22 @@ depth findMaxWidth(const CastleProto &proto) { return max_width; } +depth findMinWidth(const CastleProto &proto, u32 top) { + if (!contains(proto.repeats, top)) { + assert(0); // should not happen + return depth::infinity(); + } + return proto.repeats.at(top).bounds.min; +} + +depth findMaxWidth(const CastleProto &proto, u32 top) { + if (!contains(proto.repeats, top)) { + assert(0); // should not happen + return depth(0); + } + return proto.repeats.at(top).bounds.max; +} + CastleProto::CastleProto(const PureRepeat &pr) { assert(pr.reach.any()); assert(pr.reports.size() == 1); diff --git a/src/nfa/castlecompile.h b/src/nfa/castlecompile.h index fbafb606..a35f229d 100644 --- a/src/nfa/castlecompile.h +++ b/src/nfa/castlecompile.h @@ -85,6 +85,8 @@ struct CastleProto { std::set all_reports(const CastleProto &proto); depth findMinWidth(const CastleProto &proto); depth findMaxWidth(const CastleProto &proto); +depth findMinWidth(const CastleProto &proto, u32 top); +depth findMaxWidth(const CastleProto &proto, u32 top); /** * \brief Remap tops to be contiguous. diff --git a/src/rose/rose_build_impl.h b/src/rose/rose_build_impl.h index 26a7c606..3112d639 100644 --- a/src/rose/rose_build_impl.h +++ b/src/rose/rose_build_impl.h @@ -130,6 +130,8 @@ private: friend depth findMinWidth(const suffix_id &s); friend depth findMaxWidth(const suffix_id &s); + friend depth findMinWidth(const suffix_id &s, u32 top); + friend depth findMaxWidth(const suffix_id &s, u32 top); }; std::set all_reports(const suffix_id &s); @@ -138,6 +140,8 @@ bool has_eod_accepts(const suffix_id &s); bool has_non_eod_accepts(const suffix_id &s); depth findMinWidth(const suffix_id &s); depth findMaxWidth(const suffix_id &s); +depth findMinWidth(const suffix_id &s, u32 top); +depth findMaxWidth(const suffix_id &s, u32 top); size_t hash_value(const suffix_id &s); /** \brief represents an engine to the left of a rose role */ diff --git a/src/rose/rose_build_misc.cpp b/src/rose/rose_build_misc.cpp index 1d58c241..b8775912 100644 --- a/src/rose/rose_build_misc.cpp +++ b/src/rose/rose_build_misc.cpp @@ -907,6 +907,18 @@ depth findMinWidth(const suffix_id &s) { } } +depth findMinWidth(const suffix_id &s, u32 top) { + assert(s.graph() || s.castle() || s.haig() || s.dfa()); + // TODO: take top into account for non-castle suffixes. + if (s.graph()) { + return findMinWidth(*s.graph()); + } else if (s.castle()) { + return findMinWidth(*s.castle(), top); + } else { + return s.dfa_min_width; + } +} + depth findMaxWidth(const suffix_id &s) { assert(s.graph() || s.castle() || s.haig() || s.dfa()); if (s.graph()) { @@ -918,6 +930,18 @@ depth findMaxWidth(const suffix_id &s) { } } +depth findMaxWidth(const suffix_id &s, u32 top) { + assert(s.graph() || s.castle() || s.haig() || s.dfa()); + // TODO: take top into account for non-castle suffixes. + if (s.graph()) { + return findMaxWidth(*s.graph()); + } else if (s.castle()) { + return findMaxWidth(*s.castle(), top); + } else { + return s.dfa_max_width; + } +} + bool has_eod_accepts(const suffix_id &s) { assert(s.graph() || s.castle() || s.haig() || s.dfa()); if (s.graph()) { diff --git a/src/rose/rose_build_width.cpp b/src/rose/rose_build_width.cpp index 2a7f2bd6..6bfcee48 100644 --- a/src/rose/rose_build_width.cpp +++ b/src/rose/rose_build_width.cpp @@ -94,10 +94,11 @@ u32 findMinWidth(const RoseBuildImpl &tbi, enum rose_literal_table table) { } if (g[v].suffix) { - depth suffix_width = findMinWidth(g[v].suffix); + depth suffix_width = findMinWidth(g[v].suffix, g[v].suffix.top); assert(suffix_width.is_reachable()); - DEBUG_PRINTF("%zu has suffix (width %s), can fire report at %u\n", - g[v].idx, suffix_width.str().c_str(), + DEBUG_PRINTF("%zu has suffix with top %u (width %s), can fire " + "report at %u\n", + g[v].idx, g[v].suffix.top, suffix_width.str().c_str(), w + suffix_width); minWidth = min(minWidth, w + suffix_width); } @@ -146,8 +147,9 @@ u32 findMaxBAWidth(const RoseBuildImpl &tbi) { if (has_non_eod_accepts(g[v].suffix)) { return ROSE_BOUND_INF; } - depth suffix_width = findMaxWidth(g[v].suffix); - DEBUG_PRINTF("suffix max width %s\n", suffix_width.str().c_str()); + depth suffix_width = findMaxWidth(g[v].suffix, g[v].suffix.top); + DEBUG_PRINTF("suffix max width for top %u is %s\n", g[v].suffix.top, + suffix_width.str().c_str()); assert(suffix_width.is_reachable()); if (!suffix_width.is_finite()) { DEBUG_PRINTF("suffix too wide\n");