mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
rose: remap reports to program offsets
This commit is contained in:
committed by
Matthew Barr
parent
f40aa6bd40
commit
611579511c
@@ -50,6 +50,7 @@
|
||||
#include "util/make_unique.h"
|
||||
#include "util/multibit_build.h"
|
||||
#include "util/multibit_internal.h"
|
||||
#include "util/report_manager.h"
|
||||
#include "util/ue2_containers.h"
|
||||
#include "util/verify_types.h"
|
||||
#include "grey.h"
|
||||
@@ -990,4 +991,29 @@ unique_ptr<NGHolder> makeHolder(const CastleProto &proto, nfa_kind kind,
|
||||
return g;
|
||||
}
|
||||
|
||||
static
|
||||
void remapReportsToPrograms(PureRepeat &pr, const ReportManager &rm) {
|
||||
if (pr.reports.empty()) {
|
||||
return;
|
||||
}
|
||||
auto old_reports = pr.reports;
|
||||
pr.reports.clear();
|
||||
for (const auto &r : old_reports) {
|
||||
pr.reports.insert(rm.getProgramOffset(r));
|
||||
}
|
||||
}
|
||||
|
||||
void remapReportsToPrograms(CastleProto &castle, const ReportManager &rm) {
|
||||
for (auto &m : castle.repeats) {
|
||||
remapReportsToPrograms(m.second, rm);
|
||||
}
|
||||
|
||||
auto old_report_map = castle.report_map;
|
||||
castle.report_map.clear();
|
||||
for (auto &m : old_report_map) {
|
||||
u32 program = rm.getProgramOffset(m.first);
|
||||
castle.report_map[program].insert(begin(m.second), end(m.second));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ue2
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -51,6 +51,7 @@ namespace ue2 {
|
||||
|
||||
class CharReach;
|
||||
class NGHolder;
|
||||
class ReportManager;
|
||||
struct CompileContext;
|
||||
|
||||
/**
|
||||
@@ -158,6 +159,8 @@ bool requiresDedupe(const CastleProto &proto,
|
||||
std::unique_ptr<NGHolder> makeHolder(const CastleProto &castle, nfa_kind kind,
|
||||
const CompileContext &cc);
|
||||
|
||||
void remapReportsToPrograms(CastleProto &castle, const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif // NFA_CASTLECOMPILE_H
|
||||
|
68
src/nfa/goughcompile_util.cpp
Normal file
68
src/nfa/goughcompile_util.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "goughcompile.h"
|
||||
#include "goughcompile_util.h"
|
||||
#include "mcclellancompile_util.h"
|
||||
#include "util/report_manager.h"
|
||||
|
||||
#include "ue2common.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ue2;
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
static
|
||||
void remapReportsToPrograms(set<som_report> &reports,
|
||||
const ReportManager &rm) {
|
||||
if (reports.empty()) {
|
||||
return;
|
||||
}
|
||||
auto old_reports = reports;
|
||||
reports.clear();
|
||||
for (const auto &r : old_reports) {
|
||||
u32 program = rm.getProgramOffset(r.report);
|
||||
reports.emplace(program, r.slot);
|
||||
}
|
||||
}
|
||||
|
||||
void remapReportsToPrograms(raw_som_dfa &haig, const ReportManager &rm) {
|
||||
DEBUG_PRINTF("remap haig reports\n");
|
||||
|
||||
for (auto &ds : haig.state_som) {
|
||||
remapReportsToPrograms(ds.reports, rm);
|
||||
remapReportsToPrograms(ds.reports_eod, rm);
|
||||
}
|
||||
|
||||
// McClellan-style reports too.
|
||||
raw_dfa &rdfa = haig;
|
||||
remapReportsToPrograms(rdfa, rm);
|
||||
}
|
||||
|
||||
} // namespace ue2
|
41
src/nfa/goughcompile_util.h
Normal file
41
src/nfa/goughcompile_util.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef GOUGHCOMPILE_UTIL_H
|
||||
#define GOUGHCOMPILE_UTIL_H
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
struct raw_som_dfa;
|
||||
class ReportManager;
|
||||
|
||||
void remapReportsToPrograms(raw_som_dfa &haig, const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif // GOUGHCOMPILE_UTIL_H
|
@@ -395,4 +395,27 @@ dstate_id_t get_sds_or_proxy(const raw_dfa &raw) {
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void remapReportsToPrograms(flat_set<ReportID> &reports,
|
||||
const ReportManager &rm) {
|
||||
if (reports.empty()) {
|
||||
return;
|
||||
}
|
||||
auto old_reports = reports;
|
||||
reports.clear();
|
||||
for (const ReportID &id : old_reports) {
|
||||
u32 program = rm.getProgramOffset(id);
|
||||
reports.insert(program);
|
||||
}
|
||||
}
|
||||
|
||||
void remapReportsToPrograms(raw_dfa &rdfa, const ReportManager &rm) {
|
||||
DEBUG_PRINTF("remap dfa reports\n");
|
||||
for (auto &ds : rdfa.states) {
|
||||
remapReportsToPrograms(ds.reports, rm);
|
||||
remapReportsToPrograms(ds.reports_eod, rm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ue2
|
||||
|
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "rdfa.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/report_manager.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
@@ -57,6 +58,8 @@ size_t hash_dfa(const raw_dfa &rdfa);
|
||||
|
||||
dstate_id_t get_sds_or_proxy(const raw_dfa &raw);
|
||||
|
||||
void remapReportsToPrograms(raw_dfa &rdfa, const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user