mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
mpv: native report remapping
This commit is contained in:
parent
c101beb541
commit
ee7f31ac39
@ -36,6 +36,7 @@
|
|||||||
#include "util/alloc.h"
|
#include "util/alloc.h"
|
||||||
#include "util/multibit_internal.h"
|
#include "util/multibit_internal.h"
|
||||||
#include "util/order_check.h"
|
#include "util/order_check.h"
|
||||||
|
#include "util/report_manager.h"
|
||||||
#include "util/verify_types.h"
|
#include "util/verify_types.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -82,13 +83,21 @@ struct ClusterKey {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static
|
static
|
||||||
void writePuffette(mpv_puffette *out, const raw_puff &rp) {
|
void writePuffette(mpv_puffette *out, const raw_puff &rp,
|
||||||
|
const ReportManager &rm) {
|
||||||
DEBUG_PRINTF("outputting %u %d %u to %p\n", rp.repeats, (int)rp.unbounded,
|
DEBUG_PRINTF("outputting %u %d %u to %p\n", rp.repeats, (int)rp.unbounded,
|
||||||
rp.report, out);
|
rp.report, out);
|
||||||
out->repeats = rp.repeats;
|
out->repeats = rp.repeats;
|
||||||
out->unbounded = rp.unbounded;
|
out->unbounded = rp.unbounded;
|
||||||
out->simple_exhaust = rp.simple_exhaust;
|
out->simple_exhaust = rp.simple_exhaust;
|
||||||
out->report = rp.report;
|
out->report = rm.getProgramOffset(rp.report);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void writeSentinel(mpv_puffette *out) {
|
||||||
|
DEBUG_PRINTF("outputting sentinel to %p\n", out);
|
||||||
|
memset(out, 0, sizeof(*out));
|
||||||
|
out->report = INVALID_REPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -147,8 +156,8 @@ void populateClusters(const vector<raw_puff> &puffs_in,
|
|||||||
|
|
||||||
static
|
static
|
||||||
void writeKiloPuff(const map<ClusterKey, vector<raw_puff>>::const_iterator &it,
|
void writeKiloPuff(const map<ClusterKey, vector<raw_puff>>::const_iterator &it,
|
||||||
u32 counter_offset, mpv *m, mpv_kilopuff *kp,
|
const ReportManager &rm, u32 counter_offset, mpv *m,
|
||||||
mpv_puffette **pa) {
|
mpv_kilopuff *kp, mpv_puffette **pa) {
|
||||||
const CharReach &reach = it->first.reach;
|
const CharReach &reach = it->first.reach;
|
||||||
const vector<raw_puff> &puffs = it->second;
|
const vector<raw_puff> &puffs = it->second;
|
||||||
|
|
||||||
@ -181,11 +190,11 @@ void writeKiloPuff(const map<ClusterKey, vector<raw_puff>>::const_iterator &it,
|
|||||||
kp->puffette_offset = verify_u32((char *)*pa - (char *)m);
|
kp->puffette_offset = verify_u32((char *)*pa - (char *)m);
|
||||||
for (size_t i = 0; i < puffs.size(); i++) {
|
for (size_t i = 0; i < puffs.size(); i++) {
|
||||||
assert(!it->first.auto_restart || puffs[i].unbounded);
|
assert(!it->first.auto_restart || puffs[i].unbounded);
|
||||||
writePuffette(*pa + i, puffs[i]);
|
writePuffette(*pa + i, puffs[i], rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pa += puffs.size();
|
*pa += puffs.size();
|
||||||
writePuffette(*pa, raw_puff(0U, false, INVALID_REPORT, CharReach()));
|
writeSentinel(*pa);
|
||||||
++*pa;
|
++*pa;
|
||||||
|
|
||||||
writeDeadPoint(kp, puffs);
|
writeDeadPoint(kp, puffs);
|
||||||
@ -300,7 +309,8 @@ const mpv_counter_info &findCounter(const vector<mpv_counter_info> &counters,
|
|||||||
}
|
}
|
||||||
|
|
||||||
aligned_unique_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
aligned_unique_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
||||||
const vector<raw_puff> &triggered_puffs) {
|
const vector<raw_puff> &triggered_puffs,
|
||||||
|
const ReportManager &rm) {
|
||||||
assert(!puffs_in.empty() || !triggered_puffs.empty());
|
assert(!puffs_in.empty() || !triggered_puffs.empty());
|
||||||
u32 puffette_count = puffs_in.size() + triggered_puffs.size();
|
u32 puffette_count = puffs_in.size() + triggered_puffs.size();
|
||||||
|
|
||||||
@ -340,7 +350,7 @@ aligned_unique_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
|||||||
+ sizeof(mpv_counter_info) * counters.size());
|
+ sizeof(mpv_counter_info) * counters.size());
|
||||||
mpv_puffette *pa = pa_base;
|
mpv_puffette *pa = pa_base;
|
||||||
|
|
||||||
writePuffette(pa, raw_puff(0U, false, INVALID_REPORT, CharReach()));
|
writeSentinel(pa);
|
||||||
|
|
||||||
++pa; /* skip init sentinel */
|
++pa; /* skip init sentinel */
|
||||||
|
|
||||||
@ -366,8 +376,9 @@ aligned_unique_ptr<NFA> mpvCompile(const vector<raw_puff> &puffs_in,
|
|||||||
mpv_kilopuff *kp_begin = (mpv_kilopuff *)(m + 1);
|
mpv_kilopuff *kp_begin = (mpv_kilopuff *)(m + 1);
|
||||||
mpv_kilopuff *kp = kp_begin;
|
mpv_kilopuff *kp = kp_begin;
|
||||||
for (auto it = puff_clusters.begin(); it != puff_clusters.end(); ++it) {
|
for (auto it = puff_clusters.begin(); it != puff_clusters.end(); ++it) {
|
||||||
writeKiloPuff(it, findCounter(counters, kp - kp_begin).counter_offset,
|
writeKiloPuff(it, rm,
|
||||||
m, kp, &pa);
|
findCounter(counters, kp - kp_begin).counter_offset, m,
|
||||||
|
kp, &pa);
|
||||||
++kp;
|
++kp;
|
||||||
}
|
}
|
||||||
assert((char *)pa == (char *)nfa.get() + len);
|
assert((char *)pa == (char *)nfa.get() + len);
|
||||||
|
@ -40,6 +40,8 @@ struct NFA;
|
|||||||
|
|
||||||
namespace ue2 {
|
namespace ue2 {
|
||||||
|
|
||||||
|
class ReportManager;
|
||||||
|
|
||||||
struct raw_puff {
|
struct raw_puff {
|
||||||
raw_puff(u32 repeats_in, bool unbounded_in, ReportID report_in,
|
raw_puff(u32 repeats_in, bool unbounded_in, ReportID report_in,
|
||||||
const CharReach &reach_in, bool auto_restart_in = false,
|
const CharReach &reach_in, bool auto_restart_in = false,
|
||||||
@ -59,9 +61,9 @@ struct raw_puff {
|
|||||||
* puffs in the triggered_puffs vector are enabled when an TOP_N event is
|
* puffs in the triggered_puffs vector are enabled when an TOP_N event is
|
||||||
* delivered corresponding to their index in the vector
|
* delivered corresponding to their index in the vector
|
||||||
*/
|
*/
|
||||||
aligned_unique_ptr<NFA>
|
aligned_unique_ptr<NFA> mpvCompile(const std::vector<raw_puff> &puffs,
|
||||||
mpvCompile(const std::vector<raw_puff> &puffs,
|
const std::vector<raw_puff> &triggered_puffs,
|
||||||
const std::vector<raw_puff> &triggered_puffs);
|
const ReportManager &rm);
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
|
||||||
|
@ -1333,16 +1333,6 @@ aligned_unique_ptr<NFA> buildOutfix(RoseBuildImpl &build, OutfixInfo &outfix) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
void remapReportsToPrograms(MpvProto &mpv, const ReportManager &rm) {
|
|
||||||
for (auto &puff : mpv.puffettes) {
|
|
||||||
puff.report = rm.getProgramOffset(puff.report);
|
|
||||||
}
|
|
||||||
for (auto &puff : mpv.triggered_puffettes) {
|
|
||||||
puff.report = rm.getProgramOffset(puff.report);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void prepMpv(RoseBuildImpl &tbi, build_context &bc, size_t *historyRequired,
|
void prepMpv(RoseBuildImpl &tbi, build_context &bc, size_t *historyRequired,
|
||||||
bool *mpv_as_outfix) {
|
bool *mpv_as_outfix) {
|
||||||
@ -1365,9 +1355,7 @@ void prepMpv(RoseBuildImpl &tbi, build_context &bc, size_t *historyRequired,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto *mpv = mpv_outfix->mpv();
|
auto *mpv = mpv_outfix->mpv();
|
||||||
auto tmp = *mpv; // copy
|
auto nfa = mpvCompile(mpv->puffettes, mpv->triggered_puffettes, tbi.rm);
|
||||||
remapReportsToPrograms(tmp, tbi.rm);
|
|
||||||
auto nfa = mpvCompile(tmp.puffettes, tmp.triggered_puffettes);
|
|
||||||
assert(nfa);
|
assert(nfa);
|
||||||
if (!nfa) {
|
if (!nfa) {
|
||||||
throw CompileError("Unable to generate bytecode.");
|
throw CompileError("Unable to generate bytecode.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user