mcclellan, gough: native report remapping

This commit is contained in:
Justin Viiret
2016-04-19 11:53:10 +10:00
committed by Matthew Barr
parent 611579511c
commit 1f41a921f2
16 changed files with 112 additions and 198 deletions

View File

@@ -1039,6 +1039,7 @@ bool canImplementGraph(RoseBuildImpl *tbi, const RoseInGraph &in, NGHolder &h,
}
break;
case NFA_REV_PREFIX:
case NFA_OUTFIX_RAW:
DEBUG_PRINTF("kind %u\n", (u32)h.kind);
assert(0);
}

View File

@@ -660,7 +660,7 @@ int addAutomaton(RoseBuildImpl &tbi, const NGHolder &h, ReportID *remap) {
Automaton_Holder autom(h);
unique_ptr<raw_dfa> out_dfa = ue2::make_unique<raw_dfa>(NFA_OUTFIX);
unique_ptr<raw_dfa> out_dfa = ue2::make_unique<raw_dfa>(NFA_OUTFIX_RAW);
if (!determinise(autom, out_dfa->states, MAX_DFA_STATES)) {
return finalise_out(tbi, h, autom, move(out_dfa), remap);
}
@@ -721,7 +721,7 @@ void buildSimpleDfas(const RoseBuildImpl &tbi,
NGHolder h;
populate_holder(simple.first, exit_ids, &h);
Automaton_Holder autom(h);
unique_ptr<raw_dfa> rdfa = ue2::make_unique<raw_dfa>(NFA_OUTFIX);
unique_ptr<raw_dfa> rdfa = ue2::make_unique<raw_dfa>(NFA_OUTFIX_RAW);
UNUSED int rv = determinise(autom, rdfa->states, MAX_DFA_STATES);
assert(!rv);
rdfa->start_anchored = INIT_STATE;
@@ -771,7 +771,8 @@ vector<unique_ptr<raw_dfa>> getAnchoredDfas(RoseBuildImpl &build) {
static
size_t buildNfas(vector<raw_dfa> &anchored_dfas,
vector<aligned_unique_ptr<NFA>> *nfas,
vector<u32> *start_offset, const CompileContext &cc) {
vector<u32> *start_offset, const CompileContext &cc,
const ReportManager &rm) {
const size_t num_dfas = anchored_dfas.size();
nfas->reserve(num_dfas);
@@ -785,7 +786,7 @@ size_t buildNfas(vector<raw_dfa> &anchored_dfas,
minimize_hopcroft(rdfa, cc.grey);
auto nfa = mcclellanCompile(rdfa, cc);
auto nfa = mcclellanCompile(rdfa, cc, rm);
if (!nfa) {
assert(0);
throw std::bad_alloc();
@@ -836,7 +837,7 @@ buildAnchoredMatcher(RoseBuildImpl &build, vector<raw_dfa> &dfas,
vector<aligned_unique_ptr<NFA>> nfas;
vector<u32> start_offset; // start offset for each dfa (dots removed)
size_t total_size = buildNfas(dfas, &nfas, &start_offset, cc);
size_t total_size = buildNfas(dfas, &nfas, &start_offset, cc, build.rm);
if (total_size > cc.grey.limitRoseAnchoredSize) {
throw ResourceLimitError();

View File

@@ -43,7 +43,6 @@
#include "hwlm/hwlm.h" /* engine types */
#include "nfa/castlecompile.h"
#include "nfa/goughcompile.h"
#include "nfa/goughcompile_util.h"
#include "nfa/mcclellancompile.h"
#include "nfa/mcclellancompile_util.h"
#include "nfa/nfa_api_queue.h"
@@ -895,17 +894,13 @@ buildSuffix(const ReportManager &rm, const SomSlotManager &ssm,
}
if (suff.haig()) {
auto remapped_haig = *suff.haig();
remapReportsToPrograms(remapped_haig, rm);
auto n = goughCompile(remapped_haig, ssm.somPrecision(), cc);
auto n = goughCompile(*suff.haig(), ssm.somPrecision(), cc, rm);
assert(n);
return n;
}
if (suff.dfa()) {
auto remapped_rdfa = *suff.dfa();
remapReportsToPrograms(remapped_rdfa, rm);
auto d = mcclellanCompile(remapped_rdfa, cc);
auto d = mcclellanCompile(*suff.dfa(), cc, rm);
assert(d);
return d;
}
@@ -936,8 +931,7 @@ buildSuffix(const ReportManager &rm, const SomSlotManager &ssm,
auto rdfa = buildMcClellan(holder, &rm, false, triggers.at(0),
cc.grey);
if (rdfa) {
remapReportsToPrograms(*rdfa, rm);
auto d = mcclellanCompile(*rdfa, cc);
auto d = mcclellanCompile(*rdfa, cc, rm);
assert(d);
if (cc.grey.roseMcClellanSuffix != 2) {
n = pickImpl(move(d), move(n));
@@ -1024,6 +1018,8 @@ makeLeftNfa(const RoseBuildImpl &tbi, left_id &left,
const bool is_prefix, const bool is_transient,
const map<left_id, set<PredTopPair> > &infixTriggers,
const CompileContext &cc) {
const ReportManager &rm = tbi.rm;
aligned_unique_ptr<NFA> n;
// Should compress state if this rose is non-transient and we're in
@@ -1054,12 +1050,12 @@ makeLeftNfa(const RoseBuildImpl &tbi, left_id &left,
}
if (left.dfa()) {
n = mcclellanCompile(*left.dfa(), cc);
n = mcclellanCompile(*left.dfa(), cc, rm);
} else if (left.graph() && cc.grey.roseMcClellanPrefix == 2 && is_prefix &&
!is_transient) {
auto rdfa = buildMcClellan(*left.graph(), nullptr, cc.grey);
if (rdfa) {
n = mcclellanCompile(*rdfa, cc);
n = mcclellanCompile(*rdfa, cc, rm);
}
}
@@ -1083,7 +1079,7 @@ makeLeftNfa(const RoseBuildImpl &tbi, left_id &left,
&& (!n || !has_bounded_repeats_other_than_firsts(*n) || !is_fast(*n))) {
auto rdfa = buildMcClellan(*left.graph(), nullptr, cc.grey);
if (rdfa) {
auto d = mcclellanCompile(*rdfa, cc);
auto d = mcclellanCompile(*rdfa, cc, rm);
assert(d);
n = pickImpl(move(d), move(n));
}
@@ -1115,6 +1111,7 @@ bool buildLeftfixes(const RoseBuildImpl &tbi, build_context &bc,
bool do_prefix) {
const RoseGraph &g = tbi.g;
const CompileContext &cc = tbi.cc;
const ReportManager &rm = tbi.rm;
ue2::unordered_map<left_id, u32> seen; // already built queue indices
@@ -1165,7 +1162,8 @@ bool buildLeftfixes(const RoseBuildImpl &tbi, build_context &bc,
// Need to build NFA, which is either predestined to be a Haig (in
// SOM mode) or could be all manner of things.
if (leftfix.haig()) {
nfa = goughCompile(*leftfix.haig(), tbi.ssm.somPrecision(), cc);
nfa = goughCompile(*leftfix.haig(), tbi.ssm.somPrecision(), cc,
rm);
} else {
assert(tbi.isNonRootSuccessor(v) != tbi.isRootSuccessor(v));
nfa = makeLeftNfa(tbi, leftfix, is_prefix, is_transient,
@@ -1278,16 +1276,13 @@ public:
aligned_unique_ptr<NFA> operator()(unique_ptr<raw_dfa> &rdfa) const {
// Unleash the McClellan!
raw_dfa tmp(*rdfa);
remapReportsToPrograms(tmp, build.rm);
return mcclellanCompile(tmp, build.cc);
return mcclellanCompile(*rdfa, build.cc, build.rm);
}
aligned_unique_ptr<NFA> operator()(unique_ptr<raw_som_dfa> &haig) const {
// Unleash the Goughfish!
raw_som_dfa tmp(*haig);
remapReportsToPrograms(tmp, build.rm);
return goughCompile(tmp, build.ssm.somPrecision(), build.cc);
return goughCompile(*haig, build.ssm.somPrecision(), build.cc,
build.rm);
}
aligned_unique_ptr<NFA> operator()(unique_ptr<NGHolder> &holder) const {
@@ -1309,7 +1304,7 @@ public:
!has_bounded_repeats_other_than_firsts(*n)) {
auto rdfa = buildMcClellan(h, &rm, cc.grey);
if (rdfa) {
auto d = mcclellanCompile(*rdfa, cc);
auto d = mcclellanCompile(*rdfa, cc, rm);
if (d) {
n = pickImpl(move(d), move(n));
}

View File

@@ -73,6 +73,8 @@ string to_string(nfa_kind k) {
return "o";
case NFA_REV_PREFIX:
return "r";
case NFA_OUTFIX_RAW:
return "O";
}
assert(0);
return "?";