return MO_CONTINUE_MATCHING;
}
+/**
+ * \brief Adapts an NfaCallback to the rose callback specified in the
+ * RoseContext.
+ */
+static
+int eodNfaCallback(u64a offset, ReportID report, void *context) {
+ struct hs_scratch *scratch = context;
+ assert(scratch->magic == SCRATCH_MAGIC);
+ return scratch->tctxt.cb(offset, report, scratch);
+}
+
+/**
+ * \brief Adapts a SomNfaCallback to the rose SOM callback specified in the
+ * RoseContext.
+ */
+static
+int eodNfaSomCallback(u64a from_offset, u64a to_offset, ReportID report,
+ void *context) {
+ struct hs_scratch *scratch = context;
+ assert(scratch->magic == SCRATCH_MAGIC);
+ return scratch->tctxt.cb_som(from_offset, to_offset, report, scratch);
+}
+
/**
* \brief Check for (and deliver) reports from active output-exposed (suffix
* or outfix) NFAs.
nfaExpandState(nfa, fstate, sstate, offset, key);
}
- if (nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
- scratch->tctxt.cb_som,
+ if (nfaCheckFinalState(nfa, fstate, sstate, offset, eodNfaCallback,
+ eodNfaSomCallback,
scratch) == MO_HALT_MATCHING) {
DEBUG_PRINTF("user instructed us to stop\n");
return;
* history buffer. */
char rv = nfaQueueExecRose(q->nfa, q, MO_INVALID_IDX);
if (rv) { /* nfa is still alive */
- if (nfaCheckFinalState(nfa, fstate, sstate, offset,
- scratch->tctxt.cb, scratch->tctxt.cb_som,
+ if (nfaCheckFinalState(nfa, fstate, sstate, offset, eodNfaCallback,
+ eodNfaSomCallback,
scratch) == MO_HALT_MATCHING) {
DEBUG_PRINTF("user instructed us to stop\n");
return;
}
static really_inline
-int roseAdaptor_i(u64a offset, ReportID id, void *context, char is_simple,
- char do_som) {
+int roseAdaptor_i(u64a offset, ReportID id, struct hs_scratch *scratch,
+ char is_simple, char do_som) {
assert(id != MO_INVALID_IDX); // Should never get an invalid ID.
+ assert(scratch);
+ assert(scratch->magic == SCRATCH_MAGIC);
- struct hs_scratch *scratch = (struct hs_scratch *)context;
struct core_info *ci = &scratch->core_info;
const struct RoseEngine *rose = ci->rose;
DEBUG_PRINTF("internal report %u\n", id);
static really_inline
int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id,
- void *context, char is_simple) {
+ struct hs_scratch *scratch, char is_simple) {
assert(id != MO_INVALID_IDX); // Should never get an invalid ID.
+ assert(scratch);
+ assert(scratch->magic == SCRATCH_MAGIC);
u32 flags = 0;
- struct hs_scratch *scratch = (struct hs_scratch *)context;
struct core_info *ci = &scratch->core_info;
const struct RoseEngine *rose = ci->rose;
const struct internal_report *ri = getInternalReport(rose, id);
}
static
-int roseAdaptor(u64a offset, ReportID id, void *context) {
- return roseAdaptor_i(offset, id, context, 0, 0);
+int roseAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
+ return roseAdaptor_i(offset, id, scratch, 0, 0);
}
static
}
static
-int roseSimpleAdaptor(u64a offset, ReportID id, void *context) {
- return roseAdaptor_i(offset, id, context, 1, 0);
+int roseSimpleAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
+ return roseAdaptor_i(offset, id, scratch, 1, 0);
}
static
}
static
-int roseSomAdaptor(u64a offset, ReportID id, void *context) {
- return roseAdaptor_i(offset, id, context, 0, 1);
+int roseSomAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
+ return roseAdaptor_i(offset, id, scratch, 0, 1);
}
static
}
static
-int roseSimpleSomAdaptor(u64a offset, ReportID id, void *context) {
- return roseAdaptor_i(offset, id, context, 1, 1);
+int roseSimpleSomAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
+ return roseAdaptor_i(offset, id, scratch, 1, 1);
}
static
static
int roseSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
- void *context) {
- return roseSomAdaptor_i(from_offset, to_offset, id, context, 0);
+ struct hs_scratch *scratch) {
+ return roseSomAdaptor_i(from_offset, to_offset, id, scratch, 0);
}
static
int roseSimpleSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
- void *context) {
- return roseSomAdaptor_i(from_offset, to_offset, id, context, 1);
+ struct hs_scratch *scratch) {
+ return roseSomAdaptor_i(from_offset, to_offset, id, scratch, 1);
}
static really_inline
return is_simple ? roseSimpleSomSomAdaptor : roseSomSomAdaptor;
}
+static
+int outfixSimpleSomAdaptor(u64a offset, ReportID id, void *context) {
+ return roseAdaptor_i(offset, id, context, 1, 1);
+}
+
+static
+int outfixSimpleAdaptor(u64a offset, ReportID id, void *context) {
+ return roseAdaptor_i(offset, id, context, 1, 0);
+}
+
+static
+int outfixSomAdaptor(u64a offset, ReportID id, void *context) {
+ return roseAdaptor_i(offset, id, context, 0, 1);
+}
+
+static
+int outfixAdaptor(u64a offset, ReportID id, void *context) {
+ return roseAdaptor_i(offset, id, context, 0, 0);
+}
+
+static really_inline
+NfaCallback selectOutfixAdaptor(const struct RoseEngine *rose) {
+ const char is_simple = rose->simpleCallback;
+ const char do_som = rose->hasSom;
+
+ if (do_som) {
+ return is_simple ? outfixSimpleSomAdaptor : outfixSomAdaptor;
+ } else {
+ return is_simple ? outfixSimpleAdaptor : outfixAdaptor;
+ }
+}
+
+static
+int outfixSimpleSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
+ void *context) {
+ return roseSomAdaptor_i(from_offset, to_offset, id, context, 1);
+}
+
+static
+int outfixSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
+ void *context) {
+ return roseSomAdaptor_i(from_offset, to_offset, id, context, 0);
+}
+
+static really_inline
+SomNfaCallback selectOutfixSomAdaptor(const struct RoseEngine *rose) {
+ const char is_simple = rose->simpleCallback;
+ return is_simple ? outfixSimpleSomSomAdaptor : outfixSomSomAdaptor;
+}
+
static never_inline
void processReportList(const struct RoseEngine *rose, u32 base_offset,
u64a stream_offset, hs_scratch_t *scratch) {
q->length = scratch->core_info.len;
q->history = scratch->core_info.hbuf;
q->hlength = scratch->core_info.hlen;
- q->cb = selectAdaptor(t);
- q->som_cb = selectSomAdaptor(t);
+ q->cb = selectOutfixAdaptor(t);
+ q->som_cb = selectOutfixSomAdaptor(t);
q->context = scratch;
q->report_current = 0;
assert(isMcClellanType(nfa->type));
if (nfa->type == MCCLELLAN_NFA_8) {
nfaExecMcClellan8_B(nfa, smwr->start_offset, local_buffer,
- local_alen, selectAdaptor(rose), scratch);
+ local_alen, selectOutfixAdaptor(rose), scratch);
} else {
nfaExecMcClellan16_B(nfa, smwr->start_offset, local_buffer,
- local_alen, selectAdaptor(rose), scratch);
+ local_alen, selectOutfixAdaptor(rose), scratch);
}
}