static
void recordResources(RoseResources &resources, const RoseBuildImpl &build,
+ const vector<raw_dfa> &anchored_dfas,
const vector<LitFragment> &fragments) {
if (!build.outfixes.empty()) {
resources.has_outfixes = true;
break;
}
}
+
+ resources.has_anchored = !anchored_dfas.empty();
+ resources.has_anchored_multiple = anchored_dfas.size() > 1;
+ for (const auto &rdfa : anchored_dfas) {
+ if (rdfa.states.size() > 256) {
+ resources.has_anchored_large = true;
+ }
+ }
+
}
static
static
bytecode_ptr<RoseEngine> addSmallWriteEngine(const RoseBuildImpl &build,
+ const RoseResources &res,
bytecode_ptr<RoseEngine> rose) {
assert(rose);
return rose;
}
- u32 qual = roseQuality(rose.get());
+ u32 qual = roseQuality(res, rose.get());
auto smwr_engine = build.smwr.build(qual);
if (!smwr_engine) {
DEBUG_PRINTF("no smwr built\n");
build_context bc;
u32 floatingMinLiteralMatchOffset
= findMinFloatingLiteralMatch(*this, anchored_dfas);
- recordResources(bc.resources, *this, fragments);
- if (!anchored_dfas.empty()) {
- bc.resources.has_anchored = true;
- }
+ recordResources(bc.resources, *this, anchored_dfas, fragments);
bc.needs_mpv_catchup = needsMpvCatchup(*this);
makeBoundaryPrograms(*this, bc, boundary, dboundary, proto.boundary);
bc.engine_blob.write_bytes(engine.get());
// Add a small write engine if appropriate.
- engine = addSmallWriteEngine(*this, move(engine));
+ engine = addSmallWriteEngine(*this, bc.resources, move(engine));
DEBUG_PRINTF("rose done %p\n", engine.get());
#include "rose_build_misc.h"
#include "rose_build_impl.h"
+#include "rose_build_resources.h"
#include "hwlm/hwlm_literal.h"
#include "nfa/castlecompile.h"
#include "nfa/goughcompile.h"
return graph || castle || dfa || haig;
}
-u32 roseQuality(const RoseEngine *t) {
+u32 roseQuality(const RoseResources &res, const RoseEngine *t) {
/* Rose is low quality if the atable is a Mcclellan 16 or has multiple DFAs
*/
- const anchored_matcher_info *atable = getALiteralMatcher(t);
- if (atable) {
- if (atable->next_offset) {
+ if (res.has_anchored) {
+ if (res.has_anchored_multiple) {
DEBUG_PRINTF("multiple atable engines\n");
return 0;
}
- const NFA *nfa = (const NFA *)((const char *)atable + sizeof(*atable));
- if (!isSmallDfaType(nfa->type)) {
+ if (res.has_anchored_large) {
DEBUG_PRINTF("m16 atable engine\n");
return 0;
}
/* if we always run multiple engines then we are slow */
u32 always_run = 0;
- if (atable) {
+ if (res.has_anchored) {
always_run++;
}
always_run++;
}
- const HWLM *ftable = getFLiteralMatcher(t);
- if (ftable) {
+ if (res.has_floating) {
/* TODO: ignore conditional ftables, or ftables beyond smwr region */
always_run++;
}