From 9b7eca5400f5f844f485d3cda03b6c40471309bf Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 26 May 2016 10:11:19 +1000 Subject: [PATCH] rose: dump leftfix/suffix queue indices --- src/rose/rose_build_bytecode.cpp | 4 +- src/rose/rose_build_dump.cpp | 69 ++++++++++++++++++-------------- src/rose/rose_build_impl.h | 6 +++ 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index d37e95dc..dac2e79c 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -1102,7 +1102,7 @@ void setLeftNfaProperties(NFA &n, const left_id &left) { } static -bool buildLeftfixes(const RoseBuildImpl &tbi, build_context &bc, +bool buildLeftfixes(RoseBuildImpl &tbi, build_context &bc, QueueIndexFactory &qif, set *no_retrigger_queues, bool do_prefix) { const RoseGraph &g = tbi.g; @@ -1174,6 +1174,7 @@ bool buildLeftfixes(const RoseBuildImpl &tbi, build_context &bc, setLeftNfaProperties(*nfa, leftfix); qi = qif.get_queue(); + tbi.leftfix_queue_map.emplace(leftfix, qi); nfa->queueIndex = qi; if (!is_prefix && !leftfix.haig() && leftfix.graph() && @@ -1458,6 +1459,7 @@ void assignSuffixQueues(RoseBuildImpl &build, build_context &bc) { u32 queue = build.qif.get_queue(); DEBUG_PRINTF("assigning %p to queue %u\n", s.graph(), queue); bc.suffixes.emplace(s, queue); + build.suffix_queue_map.emplace(s, queue); } } diff --git a/src/rose/rose_build_dump.cpp b/src/rose/rose_build_dump.cpp index 079dd556..46d1676d 100644 --- a/src/rose/rose_build_dump.cpp +++ b/src/rose/rose_build_dump.cpp @@ -30,12 +30,13 @@ #include "rose_build_dump.h" -#include "hwlm/hwlm_build.h" #include "rose_build_impl.h" #include "rose_build_matchers.h" #include "rose/rose_dump.h" #include "rose_internal.h" #include "ue2common.h" +#include "hwlm/hwlm_build.h" +#include "nfa/castlecompile.h" #include "nfa/nfa_internal.h" #include "nfagraph/ng_dump.h" #include "som/slot_manager_dump.h" @@ -64,22 +65,40 @@ static string to_string(nfa_kind k) { switch (k) { case NFA_PREFIX: - return "p"; + return "PREFIX"; case NFA_INFIX: - return "i"; + return "INFIX"; case NFA_SUFFIX: - return "s"; + return "SUFFIX"; case NFA_OUTFIX: - return "o"; + return "OUTFIX"; case NFA_REV_PREFIX: - return "r"; + return "REV_PREFIX"; case NFA_OUTFIX_RAW: - return "O"; + return "OUTFIX_RAW"; } assert(0); return "?"; } +/** \brief Return the kind of a left_id or a suffix_id. */ +template +string render_kind(const Graph &g) { + if (g.graph()) { + return to_string(g.graph()->kind); + } + if (g.dfa()) { + return to_string(g.dfa()->kind); + } + if (g.haig()) { + return to_string(g.haig()->kind); + } + if (g.castle()) { + return to_string(g.castle()->kind); + } + return "UNKNOWN"; +} + namespace { class RoseGraphWriter { @@ -130,22 +149,12 @@ public: } if (g[v].suffix) { - os << "\\nSUFFIX (TOP " << g[v].suffix.top; - // Can't dump the queue number, but we can identify the suffix. - if (g[v].suffix.graph) { - os << ", graph=" << g[v].suffix.graph.get() << " " - << to_string(g[v].suffix.graph->kind); + suffix_id suff(g[v].suffix); + os << "\\n" << render_kind(suff) << " (top " << g[v].suffix.top; + auto it = build.suffix_queue_map.find(suff); + if (it != end(build.suffix_queue_map)) { + os << ", queue " << it->second; } - if (g[v].suffix.castle) { - os << ", castle=" << g[v].suffix.castle.get(); - } - if (g[v].suffix.rdfa) { - os << ", dfa=" << g[v].suffix.rdfa.get(); - } - if (g[v].suffix.haig) { - os << ", haig=" << g[v].suffix.haig.get(); - } - os << ")"; } @@ -154,15 +163,15 @@ public: } if (g[v].left) { - const char *roseKind = - build.isRootSuccessor(v) ? "PREFIX" : "INFIX"; - os << "\\nROSE " << roseKind; - os << " ("; - os << "report " << g[v].left.leftfix_report << ")"; - - if (g[v].left.graph) { - os << " " << to_string(g[v].left.graph->kind); + left_id left(g[v].left); + os << "\\n" << render_kind(left) << " (queue "; + auto it = build.leftfix_queue_map.find(left); + if (it != end(build.leftfix_queue_map)) { + os << it->second; + } else { + os << "??"; } + os << ", report " << g[v].left.leftfix_report << ")"; } os << "\""; diff --git a/src/rose/rose_build_impl.h b/src/rose/rose_build_impl.h index 4122e0bd..d5f75a22 100644 --- a/src/rose/rose_build_impl.h +++ b/src/rose/rose_build_impl.h @@ -541,6 +541,12 @@ public: u32 ematcher_region_size; /**< number of bytes the eod table runs over */ + /** \brief Mapping from leftfix to queue ID (used in dump code). */ + unordered_map leftfix_queue_map; + + /** \brief Mapping from suffix to queue ID (used in dump code). */ + unordered_map suffix_queue_map; + /** \brief Mapping from anchored literal ID to the original literal suffix * present when the literal was added to the literal matcher. Used for * overlap calculation in history assignment. */