mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
Rose: replace internal_report with program
Replace the use of the internal_report structure (for reports from engines, MPV etc) with the Rose program interpreter. SOM processing was reworked to use a new som_operation structure that is embedded in the appropriate instructions.
This commit is contained in:
committed by
Matthew Barr
parent
68851742cc
commit
36150bbc19
@@ -130,6 +130,7 @@ bool addComponentSom(NG &ng, NGHolder &g, const NGWrapper &w,
|
||||
|
||||
assert(g.kind == NFA_OUTFIX);
|
||||
dumpComponent(g, "haig", w.expressionIndex, comp_id, ng.cc.grey);
|
||||
makeReportsSomPass(ng.rm, g);
|
||||
auto haig = attemptToBuildHaig(g, som, ng.ssm.somPrecision(), triggers,
|
||||
ng.cc.grey);
|
||||
if (haig) {
|
||||
|
@@ -358,35 +358,38 @@ void dumpSmallWrite(const RoseEngine *rose, const Grey &grey) {
|
||||
smwrDumpNFA(smwr, false, grey.dumpPath);
|
||||
}
|
||||
|
||||
static UNUSED
|
||||
const char *irTypeToString(u8 type) {
|
||||
#define IR_TYPE_CASE(x) case x: return #x
|
||||
static
|
||||
const char *reportTypeToString(ReportType type) {
|
||||
#define REPORT_TYPE_CASE(x) case x: return #x
|
||||
switch (type) {
|
||||
IR_TYPE_CASE(EXTERNAL_CALLBACK);
|
||||
IR_TYPE_CASE(EXTERNAL_CALLBACK_SOM_REL);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_IF_UNSET);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_IF_WRITABLE);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_UNSET);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_WRITABLE);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_COPY);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_COPY_IF_WRITABLE);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_MAKE_WRITABLE);
|
||||
IR_TYPE_CASE(EXTERNAL_CALLBACK_SOM_STORED);
|
||||
IR_TYPE_CASE(EXTERNAL_CALLBACK_SOM_ABS);
|
||||
IR_TYPE_CASE(EXTERNAL_CALLBACK_SOM_REV_NFA);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_FROM);
|
||||
IR_TYPE_CASE(INTERNAL_SOM_LOC_SET_FROM_IF_WRITABLE);
|
||||
IR_TYPE_CASE(INTERNAL_ROSE_CHAIN);
|
||||
default: return "<unknown>";
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK);
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK_SOM_REL);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_IF_UNSET);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_IF_WRITABLE);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_UNSET);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_WRITABLE);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_COPY);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_COPY_IF_WRITABLE);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_MAKE_WRITABLE);
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK_SOM_STORED);
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK_SOM_ABS);
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK_SOM_REV_NFA);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_FROM);
|
||||
REPORT_TYPE_CASE(INTERNAL_SOM_LOC_SET_FROM_IF_WRITABLE);
|
||||
REPORT_TYPE_CASE(INTERNAL_ROSE_CHAIN);
|
||||
REPORT_TYPE_CASE(EXTERNAL_CALLBACK_SOM_PASS);
|
||||
}
|
||||
#undef IR_TYPE_CASE
|
||||
#undef REPORT_TYPE_CASE
|
||||
|
||||
assert(0);
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
static really_inline
|
||||
int isReverseNfaReport(const Report &ri) {
|
||||
switch (ri.type) {
|
||||
static
|
||||
int isReverseNfaReport(const Report &report) {
|
||||
switch (report.type) {
|
||||
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA:
|
||||
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_UNSET:
|
||||
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_WRITABLE:
|
||||
@@ -398,9 +401,9 @@ int isReverseNfaReport(const Report &ri) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static really_inline
|
||||
int isSomRelSetReport(const Report &ri) {
|
||||
switch (ri.type) {
|
||||
static
|
||||
int isSomRelSetReport(const Report &report) {
|
||||
switch (report.type) {
|
||||
case INTERNAL_SOM_LOC_SET:
|
||||
case INTERNAL_SOM_LOC_SET_IF_UNSET:
|
||||
case INTERNAL_SOM_LOC_SET_IF_WRITABLE:
|
||||
@@ -420,31 +423,34 @@ void dumpReportManager(const ReportManager &rm, const Grey &grey) {
|
||||
ss << grey.dumpPath << "internal_reports.txt";
|
||||
FILE *f = fopen(ss.str().c_str(), "w");
|
||||
const vector<Report> &reports = rm.reports();
|
||||
for (u32 i = 0; i < reports.size(); i++) {
|
||||
const Report &ir = reports[i];
|
||||
fprintf(f, "int %u: %s onmatch: %u", i, irTypeToString(ir.type),
|
||||
ir.onmatch);
|
||||
for (size_t i = 0; i < reports.size(); i++) {
|
||||
const Report &report = reports[i];
|
||||
fprintf(f, "%zu: %s onmatch: %u", i, reportTypeToString(report.type),
|
||||
report.onmatch);
|
||||
|
||||
u32 dkey = rm.getDkey(ir);
|
||||
u32 dkey = rm.getDkey(report);
|
||||
if (dkey != MO_INVALID_IDX) {
|
||||
fprintf(f, " dkey %u", dkey);
|
||||
}
|
||||
if (ir.ekey != MO_INVALID_IDX) {
|
||||
fprintf(f, " ekey %u", ir.ekey);
|
||||
if (report.ekey != INVALID_EKEY) {
|
||||
fprintf(f, " ekey %u", report.ekey);
|
||||
}
|
||||
if (ir.hasBounds()) {
|
||||
if (report.hasBounds()) {
|
||||
fprintf(f, " hasBounds (minOffset=%llu, maxOffset=%llu, "
|
||||
"minLength=%llu)",
|
||||
ir.minOffset, ir.maxOffset, ir.minLength);
|
||||
report.minOffset, report.maxOffset, report.minLength);
|
||||
}
|
||||
if (ir.offsetAdjust != 0) {
|
||||
fprintf(f, " offsetAdjust: %d", ir.offsetAdjust);
|
||||
if (report.quashSom) {
|
||||
fprintf(f, " quashSom");
|
||||
}
|
||||
if (isReverseNfaReport(ir)) {
|
||||
fprintf(f, " reverse nfa: %u", ir.revNfaIndex);
|
||||
if (report.offsetAdjust != 0) {
|
||||
fprintf(f, " offsetAdjust: %d", report.offsetAdjust);
|
||||
}
|
||||
if (isSomRelSetReport(ir)) {
|
||||
fprintf(f, " set, adjust: %lld", ir.somDistance);
|
||||
if (isReverseNfaReport(report)) {
|
||||
fprintf(f, " reverse nfa: %u", report.revNfaIndex);
|
||||
}
|
||||
if (isSomRelSetReport(report)) {
|
||||
fprintf(f, " set, adjust: %lld", report.somDistance);
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
@@ -293,7 +293,7 @@ void constructPuff(NGHolder &g, const NFAVertex a, const NFAVertex puffv,
|
||||
u32 squashDistance = allowedSquashDistance(cr, width, g, puffv,
|
||||
prefilter);
|
||||
|
||||
Report ir = makeRoseTrigger(event, squashDistance);
|
||||
Report ir = makeMpvTrigger(event, squashDistance);
|
||||
/* only need to trigger once if floatingUnboundedDot */
|
||||
bool floatingUnboundedDot = unbounded && cr.all() && !fixed_depth;
|
||||
if (floatingUnboundedDot) {
|
||||
|
@@ -445,8 +445,9 @@ void replaceTempSomSlot(ReportManager &rm, NGHolder &g, u32 real_slot) {
|
||||
}
|
||||
|
||||
static
|
||||
void setPrefixReports(ReportManager &rm, NGHolder &g, u8 ir_type, u32 som_loc,
|
||||
const vector<DepthMinMax> &depths, bool prefix_by_rev) {
|
||||
void setPrefixReports(ReportManager &rm, NGHolder &g, ReportType ir_type,
|
||||
u32 som_loc, const vector<DepthMinMax> &depths,
|
||||
bool prefix_by_rev) {
|
||||
Report ir = makeCallback(0U, 0);
|
||||
ir.type = ir_type;
|
||||
ir.onmatch = som_loc;
|
||||
@@ -470,7 +471,7 @@ void setPrefixReports(ReportManager &rm, NGHolder &g, u8 ir_type, u32 som_loc,
|
||||
}
|
||||
|
||||
static
|
||||
void updatePrefixReports(ReportManager &rm, NGHolder &g, u8 ir_type) {
|
||||
void updatePrefixReports(ReportManager &rm, NGHolder &g, ReportType ir_type) {
|
||||
/* update the som action on the prefix report */
|
||||
for (auto v : inv_adjacent_vertices_range(g.accept, g)) {
|
||||
auto &reports = g[v].reports;
|
||||
@@ -555,7 +556,8 @@ bool finalRegion(const NGHolder &g,
|
||||
|
||||
static
|
||||
void replaceExternalReportsWithSomRep(ReportManager &rm, NGHolder &g,
|
||||
NFAVertex v, u8 ir_type, u64a param) {
|
||||
NFAVertex v, ReportType ir_type,
|
||||
u64a param) {
|
||||
assert(!g[v].reports.empty());
|
||||
|
||||
flat_set<ReportID> r_new;
|
||||
@@ -2409,6 +2411,33 @@ bool splitOffBestLiteral(const NGHolder &g,
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the given graph's EXTERNAL_CALLBACK reports with
|
||||
* EXTERNAL_CALLBACK_SOM_PASS reports.
|
||||
*/
|
||||
void makeReportsSomPass(ReportManager &rm, NGHolder &g) {
|
||||
for (const auto &v : vertices_range(g)) {
|
||||
const auto &reports = g[v].reports;
|
||||
if (reports.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
flat_set<ReportID> new_reports;
|
||||
for (const ReportID &id : reports) {
|
||||
const Report &report = rm.getReport(id);
|
||||
if (report.type != EXTERNAL_CALLBACK) {
|
||||
new_reports.insert(id);
|
||||
continue;
|
||||
}
|
||||
Report report2 = report;
|
||||
report2.type = EXTERNAL_CALLBACK_SOM_PASS;
|
||||
new_reports.insert(rm.getInternalId(report2));
|
||||
}
|
||||
|
||||
g[v].reports = new_reports;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) {
|
||||
ue2_literal lit;
|
||||
@@ -2431,6 +2460,8 @@ bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) {
|
||||
|
||||
assert(lit.length() <= MAX_MASK2_WIDTH || !mixed_sensitivity(lit));
|
||||
|
||||
makeReportsSomPass(ng.rm, *rhs);
|
||||
|
||||
dumpHolder(*rhs, 91, "lithaig_rhs", ng.cc.grey);
|
||||
|
||||
vector<vector<CharReach> > triggers;
|
||||
@@ -2493,6 +2524,8 @@ bool doHaigLitHaigSom(NG &ng, NGHolder &g,
|
||||
return false; /* TODO: handle */
|
||||
}
|
||||
|
||||
makeReportsSomPass(ng.rm, *rhs);
|
||||
|
||||
dumpHolder(*lhs, 92, "haiglithaig_lhs", ng.cc.grey);
|
||||
dumpHolder(*rhs, 93, "haiglithaig_rhs", ng.cc.grey);
|
||||
|
||||
@@ -2628,6 +2661,8 @@ bool doMultiLitHaigSom(NG &ng, NGHolder &g, som_type som) {
|
||||
return false;
|
||||
}
|
||||
|
||||
makeReportsSomPass(ng.rm, *rhs);
|
||||
|
||||
dumpHolder(*rhs, 91, "lithaig_rhs", ng.cc.grey);
|
||||
|
||||
vector<vector<CharReach>> triggers;
|
||||
|
@@ -72,6 +72,8 @@ sombe_rv doSom(NG &ng, NGHolder &h, const NGWrapper &w, u32 comp_id,
|
||||
sombe_rv doSomWithHaig(NG &ng, NGHolder &h, const NGWrapper &w, u32 comp_id,
|
||||
som_type som);
|
||||
|
||||
void makeReportsSomPass(ReportManager &rm, NGHolder &g);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif // NG_SOM_H
|
||||
|
Reference in New Issue
Block a user