mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
nfa: unify NfaCallback and SomNfaCallback
Use just one callback type, with both start and end offsets.
This commit is contained in:
committed by
Matthew Barr
parent
9087d59be5
commit
cf9e40ae1c
@@ -281,14 +281,15 @@ restart:
|
||||
|
||||
/* for use by mpv (chained) only */
|
||||
static
|
||||
int roseNfaFinalBlastAdaptor(u64a offset, ReportID id, void *context) {
|
||||
int roseNfaFinalBlastAdaptor(u64a som, u64a offset, ReportID id,
|
||||
void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
const struct RoseEngine *t = scratch->core_info.rose;
|
||||
|
||||
DEBUG_PRINTF("masky got himself a blasted match @%llu id %u !woot!\n",
|
||||
offset, id);
|
||||
|
||||
int cb_rv = roseNfaRunProgram(t, scratch, 0, offset, id, 1);
|
||||
int cb_rv = roseNfaRunProgram(t, scratch, som, offset, id, 1);
|
||||
if (cb_rv == MO_HALT_MATCHING) {
|
||||
return MO_HALT_MATCHING;
|
||||
} else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
|
||||
@@ -394,7 +395,6 @@ hwlmcb_rv_t roseCatchUpMPV_i(const struct RoseEngine *t, s64a loc,
|
||||
assert(!q->report_current);
|
||||
|
||||
q->cb = roseNfaFinalBlastAdaptor;
|
||||
q->som_cb = NULL;
|
||||
|
||||
DEBUG_PRINTF("queue %u blasting, %u/%u [%lld/%lld]\n",
|
||||
qi, q->cur, q->end, q->items[q->cur].location, loc);
|
||||
@@ -449,7 +449,7 @@ char in_mpv(const struct RoseEngine *rose, const struct hs_scratch *scratch) {
|
||||
}
|
||||
|
||||
static
|
||||
int roseNfaBlastAdaptor(u64a offset, ReportID id, void *context) {
|
||||
int roseNfaBlastAdaptor(u64a som, u64a offset, ReportID id, void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
const struct RoseEngine *t = scratch->core_info.rose;
|
||||
@@ -458,7 +458,7 @@ int roseNfaBlastAdaptor(u64a offset, ReportID id, void *context) {
|
||||
offset, id);
|
||||
|
||||
const char from_mpv = in_mpv(t, scratch);
|
||||
int cb_rv = roseNfaRunProgram(t, scratch, 0, offset, id, from_mpv);
|
||||
int cb_rv = roseNfaRunProgram(t, scratch, som, offset, id, from_mpv);
|
||||
if (cb_rv == MO_HALT_MATCHING) {
|
||||
return MO_HALT_MATCHING;
|
||||
} else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
|
||||
@@ -470,65 +470,8 @@ int roseNfaBlastAdaptor(u64a offset, ReportID id, void *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int roseNfaBlastAdaptorNoInternal(u64a offset, ReportID id, void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
const struct RoseEngine *t = scratch->core_info.rose;
|
||||
|
||||
DEBUG_PRINTF("masky got himself a blasted match @%llu id %u !woot!\n",
|
||||
offset, id);
|
||||
|
||||
assert(!in_mpv(t, scratch));
|
||||
|
||||
int cb_rv = roseNfaRunProgram(t, scratch, 0, offset, id, 0);
|
||||
if (cb_rv == MO_HALT_MATCHING) {
|
||||
return MO_HALT_MATCHING;
|
||||
} else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
|
||||
return MO_CONTINUE_MATCHING;
|
||||
} else {
|
||||
assert(cb_rv == MO_CONTINUE_MATCHING);
|
||||
return !roseSuffixIsExhausted(t, tctxt->curr_qi,
|
||||
scratch->core_info.exhaustionVector);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int roseNfaBlastSomAdaptor(u64a from_offset, u64a offset, ReportID id,
|
||||
void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
const struct RoseEngine *t = scratch->core_info.rose;
|
||||
|
||||
DEBUG_PRINTF("masky got himself a blasted match @%llu id %u !woot!\n",
|
||||
offset, id);
|
||||
|
||||
assert(!in_mpv(t, scratch));
|
||||
|
||||
/* must be a external report as haig cannot directly participate in chain */
|
||||
int cb_rv = roseNfaRunProgram(scratch->core_info.rose, scratch, from_offset,
|
||||
offset, id, 0);
|
||||
if (cb_rv == MO_HALT_MATCHING) {
|
||||
return MO_HALT_MATCHING;
|
||||
} else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
|
||||
return MO_CONTINUE_MATCHING;
|
||||
} else {
|
||||
assert(cb_rv == MO_CONTINUE_MATCHING);
|
||||
return !roseSuffixIsExhausted(t, tctxt->curr_qi,
|
||||
scratch->core_info.exhaustionVector);
|
||||
}
|
||||
}
|
||||
|
||||
int roseNfaAdaptor(u64a offset, ReportID id, void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
DEBUG_PRINTF("masky got himself a match @%llu id %u !woot!\n", offset, id);
|
||||
|
||||
return roseNfaRunProgram(scratch->core_info.rose, scratch, 0, offset, id,
|
||||
0);
|
||||
}
|
||||
|
||||
int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id,
|
||||
void *context) {
|
||||
int roseNfaAdaptor(u64a from_offset, u64a offset, ReportID id,
|
||||
void *context) {
|
||||
struct hs_scratch *scratch = context;
|
||||
DEBUG_PRINTF("masky got himself a match @%llu id %u !woot!\n", offset, id);
|
||||
|
||||
@@ -538,24 +481,15 @@ int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id,
|
||||
}
|
||||
|
||||
static really_inline
|
||||
char blast_queue(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
struct mq *q, u32 qi, s64a to_loc, char report_current) {
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
const struct NfaInfo *info = getNfaInfoByQueue(t, qi);
|
||||
|
||||
tctxt->curr_qi = qi;
|
||||
if (info->only_external) {
|
||||
q->cb = roseNfaBlastAdaptorNoInternal;
|
||||
} else {
|
||||
q->cb = roseNfaBlastAdaptor;
|
||||
}
|
||||
char blast_queue(struct hs_scratch *scratch, struct mq *q, u32 qi, s64a to_loc,
|
||||
char report_current) {
|
||||
scratch->tctxt.curr_qi = qi;
|
||||
q->cb = roseNfaBlastAdaptor;
|
||||
q->report_current = report_current;
|
||||
q->som_cb = roseNfaBlastSomAdaptor;
|
||||
DEBUG_PRINTF("queue %u blasting, %u/%u [%lld/%lld]\n", qi, q->cur, q->end,
|
||||
q_cur_loc(q), to_loc);
|
||||
char alive = nfaQueueExec(q->nfa, q, to_loc);
|
||||
q->cb = roseNfaAdaptor;
|
||||
q->som_cb = roseNfaSomAdaptor;
|
||||
assert(!q->report_current);
|
||||
|
||||
return alive;
|
||||
@@ -585,7 +519,7 @@ hwlmcb_rv_t buildSufPQ_final(const struct RoseEngine *t, s64a report_ok_loc,
|
||||
|
||||
ensureEnd(q, a_qi, final_loc);
|
||||
|
||||
char alive = blast_queue(t, scratch, q, a_qi, second_place_loc, 0);
|
||||
char alive = blast_queue(scratch, q, a_qi, second_place_loc, 0);
|
||||
|
||||
/* We have three possible outcomes:
|
||||
* (1) the nfa died
|
||||
@@ -881,7 +815,7 @@ hwlmcb_rv_t roseCatchUpNfas(const struct RoseEngine *t, s64a loc,
|
||||
continue;
|
||||
}
|
||||
|
||||
char alive = blast_queue(t, scratch, q, qi, second_place_loc, 1);
|
||||
char alive = blast_queue(scratch, q, qi, second_place_loc, 1);
|
||||
|
||||
if (!alive) {
|
||||
if (can_stop_matching(scratch)) {
|
||||
|
@@ -211,7 +211,7 @@ event_enqueued:
|
||||
return HWLM_CONTINUE_MATCHING;
|
||||
}
|
||||
|
||||
int roseAnchoredCallback(u64a end, u32 id, void *ctx) {
|
||||
int roseAnchoredCallback(u64a som, u64a end, u32 id, void *ctx) {
|
||||
struct hs_scratch *scratch = ctx;
|
||||
struct RoseContext *tctxt = &scratch->tctxt;
|
||||
struct core_info *ci = &scratch->core_info;
|
||||
@@ -243,7 +243,6 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) {
|
||||
|
||||
const u32 *programs = getByOffset(t, t->litProgramOffset);
|
||||
assert(id < t->literalCount);
|
||||
const u64a som = 0;
|
||||
const u8 flags = ROSE_PROG_FLAG_IN_ANCHORED;
|
||||
if (roseRunProgram(t, scratch, programs[id], som, real_end, match_len,
|
||||
flags) == HWLM_TERMINATE_MATCHING) {
|
||||
@@ -648,8 +647,8 @@ int roseRunBoundaryProgram(const struct RoseEngine *rose, u32 program,
|
||||
return MO_CONTINUE_MATCHING;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
int roseReportAdaptor_i(u64a som, u64a offset, ReportID id, void *context) {
|
||||
int roseReportAdaptor(u64a som, u64a offset, ReportID id, void *context) {
|
||||
DEBUG_PRINTF("som=%llu, offset=%llu, id=%u\n", som, offset, id);
|
||||
struct hs_scratch *scratch = context;
|
||||
assert(scratch && scratch->magic == SCRATCH_MAGIC);
|
||||
|
||||
@@ -667,13 +666,3 @@ int roseReportAdaptor_i(u64a som, u64a offset, ReportID id, void *context) {
|
||||
|
||||
return can_stop_matching(scratch) ? MO_HALT_MATCHING : MO_CONTINUE_MATCHING;
|
||||
}
|
||||
|
||||
int roseReportAdaptor(u64a offset, ReportID id, void *context) {
|
||||
DEBUG_PRINTF("offset=%llu, id=%u\n", offset, id);
|
||||
return roseReportAdaptor_i(0, offset, id, context);
|
||||
}
|
||||
|
||||
int roseReportSomAdaptor(u64a som, u64a offset, ReportID id, void *context) {
|
||||
DEBUG_PRINTF("som=%llu, offset=%llu, id=%u\n", som, offset, id);
|
||||
return roseReportAdaptor_i(som, offset, id, context);
|
||||
}
|
||||
|
@@ -48,8 +48,7 @@
|
||||
|
||||
/* Callbacks, defined in catchup.c */
|
||||
|
||||
int roseNfaAdaptor(u64a offset, ReportID id, void *context);
|
||||
int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id, void *context);
|
||||
int roseNfaAdaptor(u64a from_offset, u64a offset, ReportID id, void *context);
|
||||
|
||||
/* Callbacks, defined in match.c */
|
||||
|
||||
@@ -57,7 +56,7 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctx);
|
||||
hwlmcb_rv_t roseFloatingCallback(size_t start, size_t end, u32 id, void *ctx);
|
||||
hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id,
|
||||
void *ctx);
|
||||
int roseAnchoredCallback(u64a end, u32 id, void *ctx);
|
||||
int roseAnchoredCallback(u64a som, u64a end, u32 id, void *ctx);
|
||||
|
||||
/* Common code, used all over Rose runtime */
|
||||
|
||||
@@ -82,7 +81,6 @@ void initQueue(struct mq *q, u32 qi, const struct RoseEngine *t,
|
||||
q->history = scratch->core_info.hbuf;
|
||||
q->hlength = scratch->core_info.hlen;
|
||||
q->cb = roseNfaAdaptor;
|
||||
q->som_cb = roseNfaSomAdaptor;
|
||||
q->context = scratch;
|
||||
q->report_current = 0;
|
||||
|
||||
|
@@ -722,13 +722,13 @@ u64a roseGetHaigSom(const struct RoseEngine *t, struct hs_scratch *scratch,
|
||||
u64a start = ~0ULL;
|
||||
|
||||
/* switch the callback + context for a fun one */
|
||||
q->som_cb = roseNfaEarliestSom;
|
||||
q->cb = roseNfaEarliestSom;
|
||||
q->context = &start;
|
||||
|
||||
nfaReportCurrentMatches(q->nfa, q);
|
||||
|
||||
/* restore the old callback + context */
|
||||
q->som_cb = roseNfaSomAdaptor;
|
||||
q->cb = roseNfaAdaptor;
|
||||
q->context = NULL;
|
||||
DEBUG_PRINTF("earliest som is %llu\n", start);
|
||||
return start;
|
||||
@@ -779,7 +779,7 @@ hwlmcb_rv_t roseEnginesEod(const struct RoseEngine *rose,
|
||||
}
|
||||
|
||||
if (nfaCheckFinalState(q->nfa, q->state, q->streamState, offset,
|
||||
roseReportAdaptor, roseReportSomAdaptor,
|
||||
roseReportAdaptor,
|
||||
scratch) == MO_HALT_MATCHING) {
|
||||
DEBUG_PRINTF("user instructed us to stop\n");
|
||||
return HWLM_TERMINATE_MATCHING;
|
||||
@@ -815,7 +815,7 @@ hwlmcb_rv_t roseSuffixesEod(const struct RoseEngine *rose,
|
||||
continue;
|
||||
}
|
||||
if (nfaCheckFinalState(q->nfa, q->state, q->streamState, offset,
|
||||
roseReportAdaptor, roseReportSomAdaptor,
|
||||
roseReportAdaptor,
|
||||
scratch) == MO_HALT_MATCHING) {
|
||||
DEBUG_PRINTF("user instructed us to stop\n");
|
||||
return HWLM_TERMINATE_MATCHING;
|
||||
|
@@ -49,8 +49,7 @@ void roseStreamEodExec(const struct RoseEngine *t, u64a offset,
|
||||
hwlmcb_rv_t rosePureLiteralCallback(size_t start, size_t end, u32 id,
|
||||
void *context);
|
||||
|
||||
int roseReportAdaptor(u64a offset, ReportID id, void *context);
|
||||
int roseReportSomAdaptor(u64a som, u64a offset, ReportID id, void *context);
|
||||
int roseReportAdaptor(u64a som, u64a offset, ReportID id, void *context);
|
||||
|
||||
int roseRunBoundaryProgram(const struct RoseEngine *rose, u32 program,
|
||||
u64a stream_offset, struct hs_scratch *scratch);
|
||||
|
@@ -2616,16 +2616,6 @@ bool anyEndfixMpvTriggers(const RoseBuildImpl &tbi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static
|
||||
bool hasInternalReport(const set<ReportID> &reports, const ReportManager &rm) {
|
||||
for (ReportID r : reports) {
|
||||
if (!isExternalReport(rm.getReport(r))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static
|
||||
void populateNfaInfoBasics(const RoseBuildImpl &build, const build_context &bc,
|
||||
const vector<OutfixInfo> &outfixes,
|
||||
@@ -2643,24 +2633,10 @@ void populateNfaInfoBasics(const RoseBuildImpl &build, const build_context &bc,
|
||||
info.no_retrigger = contains(no_retrigger_queues, qi) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Mark outfixes that only trigger external reports.
|
||||
// Mark outfixes that are in the small block matcher.
|
||||
for (const auto &out : outfixes) {
|
||||
const u32 qi = out.get_queue();
|
||||
|
||||
infos[qi].in_sbmatcher = out.in_sbmatcher;
|
||||
if (!hasInternalReport(all_reports(out), build.rm)) {
|
||||
infos[qi].only_external = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark suffixes that only trigger external reports.
|
||||
for (const auto &e : bc.suffixes) {
|
||||
const suffix_id &s = e.first;
|
||||
u32 qi = e.second;
|
||||
|
||||
if (!hasInternalReport(all_reports(s), build.rm)) {
|
||||
infos[qi].only_external = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark suffixes triggered by EOD table literals.
|
||||
|
@@ -156,8 +156,6 @@ struct NfaInfo {
|
||||
u32 fullStateOffset; /* offset in scratch, relative to ??? */
|
||||
u32 ekeyListOffset; /* suffix, relative to base of rose, 0 if no ekeys */
|
||||
u8 no_retrigger; /* TODO */
|
||||
u8 only_external; /**< does not raise any som internal events or chained
|
||||
* rose events */
|
||||
u8 in_sbmatcher; /**< this outfix should not be run in small-block
|
||||
* execution, as it will be handled by the sbmatcher
|
||||
* HWLM table. */
|
||||
|
Reference in New Issue
Block a user