mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
shift early_dfa construction earlier
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -1033,8 +1033,8 @@ bool empty(const GraphT &g) {
|
||||
return vi == ve;
|
||||
}
|
||||
|
||||
/* We only try to implement as a dfa if a non-nullptr as_dfa is provided to return
|
||||
* the raw dfa to. */
|
||||
/* We only try to implement as a dfa if a non-nullptr as_dfa is provided to
|
||||
* return the raw dfa to. */
|
||||
static
|
||||
bool canImplementGraph(RoseBuildImpl *tbi, const RoseInGraph &in, NGHolder &h,
|
||||
const vector<RoseInEdge> &edges, bool prefilter,
|
||||
@@ -1105,7 +1105,7 @@ bool canImplementGraph(RoseBuildImpl *tbi, const RoseInGraph &in, NGHolder &h,
|
||||
}
|
||||
|
||||
if (!generates_callbacks(h)) {
|
||||
setReportId(h, tbi->getNewNfaReport());
|
||||
set_report(h, tbi->getNewNfaReport());
|
||||
}
|
||||
|
||||
bool single_trigger = min_offset == max_offset;
|
||||
@@ -1601,6 +1601,8 @@ bool RoseBuildImpl::addRose(const RoseInGraph &ig, bool prefilter,
|
||||
|
||||
for (const auto &e : edges_range(in)) {
|
||||
if (!in[e].graph) {
|
||||
assert(!in[e].dfa);
|
||||
assert(!in[e].haig);
|
||||
continue; // no graph
|
||||
}
|
||||
|
||||
@@ -1616,6 +1618,11 @@ bool RoseBuildImpl::addRose(const RoseInGraph &ig, bool prefilter,
|
||||
ordered_graphs.push_back(h);
|
||||
}
|
||||
graphs[h].push_back(e);
|
||||
if (in[e].dfa) {
|
||||
assert(!contains(bd.early_dfas, h)
|
||||
|| bd.early_dfas[h] == in[e].dfa);
|
||||
bd.early_dfas[h] = in[e].dfa;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ordered_graphs.size() == graphs.size());
|
||||
@@ -1626,8 +1633,9 @@ bool RoseBuildImpl::addRose(const RoseInGraph &ig, bool prefilter,
|
||||
const vector<RoseInEdge> &h_edges = graphs.at(h);
|
||||
unique_ptr<raw_dfa> as_dfa;
|
||||
/* allow finalChance as fallback is basically an outfix at this point */
|
||||
if (!canImplementGraph(this, in, *h, h_edges, prefilter, rm, cc,
|
||||
finalChance, &as_dfa)) {
|
||||
if (!contains(bd.early_dfas, h)
|
||||
&& !canImplementGraph(this, in, *h, h_edges, prefilter, rm, cc,
|
||||
finalChance, &as_dfa)) {
|
||||
return false;
|
||||
}
|
||||
if (as_dfa) {
|
||||
@@ -1649,7 +1657,7 @@ bool RoseBuildImpl::addRose(const RoseInGraph &ig, bool prefilter,
|
||||
if (!generates_callbacks(whatRoseIsThis(in, e))
|
||||
&& !contains(bd.early_dfas, &h)
|
||||
&& in[target(e, in)].type != RIV_ACCEPT_EOD) {
|
||||
setReportId(h, getNewNfaReport());
|
||||
set_report(h, getNewNfaReport());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -480,7 +480,7 @@ void addTransientMask(RoseBuildImpl &build, const vector<CharReach> &mask,
|
||||
|
||||
// Everyone gets the same report ID.
|
||||
ReportID mask_report = build.getNewNfaReport();
|
||||
setReportId(*mask_graph, mask_report);
|
||||
set_report(*mask_graph, mask_report);
|
||||
|
||||
// Build the HWLM literal mask.
|
||||
vector<u8> msk, cmp;
|
||||
|
@@ -166,7 +166,7 @@ bool delayLiteralWithPrefix(RoseBuildImpl &tbi, RoseVertex v, u32 lit_id,
|
||||
|
||||
shared_ptr<NGHolder> h = makeRosePrefix(lit.s);
|
||||
ReportID prefix_report = 0;
|
||||
setReportId(*h, prefix_report);
|
||||
set_report(*h, prefix_report);
|
||||
|
||||
if (!isImplementableNFA(*h, &tbi.rm, tbi.cc)) {
|
||||
DEBUG_PRINTF("prefix not implementable\n");
|
||||
|
@@ -624,8 +624,6 @@ size_t maxOverlap(const rose_literal_id &a, const rose_literal_id &b);
|
||||
ue2_literal findNonOverlappingTail(const std::set<ue2_literal> &lits,
|
||||
const ue2_literal &s);
|
||||
|
||||
void setReportId(NGHolder &g, ReportID id);
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool roseHasTops(const RoseBuildImpl &build, RoseVertex v);
|
||||
bool hasOrphanedTops(const RoseBuildImpl &build);
|
||||
|
@@ -859,27 +859,6 @@ bool RoseDedupeAuxImpl::requiresDedupeSupport(
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets the report ID for all vertices connected to an accept to `id`.
|
||||
void setReportId(NGHolder &g, ReportID id) {
|
||||
// First, wipe the report IDs on all vertices.
|
||||
for (auto v : vertices_range(g)) {
|
||||
g[v].reports.clear();
|
||||
}
|
||||
|
||||
// Any predecessors of accept get our id.
|
||||
for (auto v : inv_adjacent_vertices_range(g.accept, g)) {
|
||||
g[v].reports.insert(id);
|
||||
}
|
||||
|
||||
// Same for preds of acceptEod, except accept itself.
|
||||
for (auto v : inv_adjacent_vertices_range(g.acceptEod, g)) {
|
||||
if (v == g.accept) {
|
||||
continue;
|
||||
}
|
||||
g[v].reports.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const RoseEdgeProps &a, const RoseEdgeProps &b) {
|
||||
ORDER_CHECK(minBound);
|
||||
ORDER_CHECK(maxBound);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -55,6 +55,7 @@ namespace ue2 {
|
||||
|
||||
class NGHolder;
|
||||
struct raw_som_dfa;
|
||||
struct raw_dfa;
|
||||
|
||||
enum RoseInVertexType {
|
||||
RIV_LITERAL,
|
||||
@@ -166,9 +167,12 @@ struct RoseInEdgeProps {
|
||||
/** \brief Maximum bound on 'dot' repeat between literals. */
|
||||
u32 maxBound;
|
||||
|
||||
/** \brief Prefix graph. Graph is end to (end - lag). */
|
||||
/** \brief Graph on edge. Graph is end to (end - lag). */
|
||||
std::shared_ptr<NGHolder> graph;
|
||||
|
||||
/** \brief DFA version of graph, if we have already determinised. */
|
||||
std::shared_ptr<raw_dfa> dfa;
|
||||
|
||||
/** \brief Haig version of graph, if required. */
|
||||
std::shared_ptr<raw_som_dfa> haig;
|
||||
|
||||
|
Reference in New Issue
Block a user