static aligned_unique_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality, const CompileContext &cc, const ReportManager &rm, u32 *start_offset, u32 *small_region) { *start_offset = remove_leading_dots(rdfa); // Unleash the McClellan! set<dstate_id_t> accel_states; auto nfa = mcclellanCompile(rdfa, cc, rm, &accel_states); if (!nfa) { DEBUG_PRINTF("mcclellan compile failed for smallwrite NFA\n"); return nullptr; } if (is_slow(rdfa, accel_states, roseQuality)) { DEBUG_PRINTF("is slow\n"); *small_region = cc.grey.smallWriteLargestBufferBad; if (*small_region <= *start_offset) { return nullptr; } if (prune_overlong(rdfa, *small_region - *start_offset)) { if (rdfa.start_anchored == DEAD_STATE) { DEBUG_PRINTF("all patterns pruned out\n"); return nullptr; } nfa = mcclellanCompile(rdfa, cc, rm, &accel_states); if (!nfa) { DEBUG_PRINTF("mcclellan compile failed for smallwrite NFA\n"); assert(0); /* able to build orig dfa but not the trimmed? */ return nullptr; } } } else { *small_region = cc.grey.smallWriteLargestBuffer; } assert(isMcClellanType(nfa->type)); if (nfa->length > cc.grey.limitSmallWriteOutfixSize || nfa->length > cc.grey.limitDFASize) { DEBUG_PRINTF("smallwrite outfix size too large\n"); return nullptr; /* this is just a soft failure - don't build smwr */ } nfa->queueIndex = 0; /* dummy, small write API does not use queue */ return nfa; }
static aligned_unique_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc, const ReportManager &rm, set<dstate_id_t> &accel_states) { aligned_unique_ptr<NFA> dfa = nullptr; if (cc.grey.allowSmallWriteSheng) { dfa = shengCompile(rdfa, cc, rm, &accel_states); } if (!dfa) { dfa = mcclellanCompile(rdfa, cc, rm, &accel_states); } return dfa; }