mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-18 02:00:36 +03:00
nfa: switch to using bytecode_ptr<NFA>
This commit is contained in:
committed by
Matthew Barr
parent
905ac78061
commit
a197074c5d
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -26,7 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
/**
|
||||
* \file
|
||||
* \brief Large Bounded Repeat (LBR) engine build code.
|
||||
*/
|
||||
|
||||
@@ -128,25 +129,24 @@ void fillNfa(NFA *nfa, lbr_common *c, ReportID report, const depth &repeatMin,
|
||||
}
|
||||
|
||||
template <class LbrStruct> static
|
||||
aligned_unique_ptr<NFA> makeLbrNfa(NFAEngineType nfa_type,
|
||||
enum RepeatType rtype,
|
||||
const depth &repeatMax) {
|
||||
bytecode_ptr<NFA> makeLbrNfa(NFAEngineType nfa_type, enum RepeatType rtype,
|
||||
const depth &repeatMax) {
|
||||
size_t tableLen = 0;
|
||||
if (rtype == REPEAT_SPARSE_OPTIMAL_P) {
|
||||
tableLen = sizeof(u64a) * (repeatMax + 1);
|
||||
}
|
||||
size_t len = sizeof(NFA) + sizeof(LbrStruct) + sizeof(RepeatInfo) +
|
||||
tableLen + sizeof(u64a);
|
||||
aligned_unique_ptr<NFA> nfa = aligned_zmalloc_unique<NFA>(len);
|
||||
auto nfa = make_bytecode_ptr<NFA>(len);
|
||||
nfa->type = verify_u8(nfa_type);
|
||||
nfa->length = verify_u32(len);
|
||||
return nfa;
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> buildLbrDot(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> buildLbrDot(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
if (!cr.all()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -164,10 +164,9 @@ aligned_unique_ptr<NFA> buildLbrDot(const CharReach &cr, const depth &repeatMin,
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> buildLbrVerm(const CharReach &cr,
|
||||
const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> buildLbrVerm(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
const CharReach escapes(~cr);
|
||||
|
||||
if (escapes.count() != 1) {
|
||||
@@ -188,10 +187,9 @@ aligned_unique_ptr<NFA> buildLbrVerm(const CharReach &cr,
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> buildLbrNVerm(const CharReach &cr,
|
||||
const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> buildLbrNVerm(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
const CharReach escapes(cr);
|
||||
|
||||
if (escapes.count() != 1) {
|
||||
@@ -212,10 +210,9 @@ aligned_unique_ptr<NFA> buildLbrNVerm(const CharReach &cr,
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> buildLbrShuf(const CharReach &cr,
|
||||
const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> buildLbrShuf(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
|
||||
is_reset);
|
||||
auto nfa = makeLbrNfa<lbr_shuf>(LBR_NFA_SHUF, rtype, repeatMax);
|
||||
@@ -233,10 +230,9 @@ aligned_unique_ptr<NFA> buildLbrShuf(const CharReach &cr,
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> buildLbrTruf(const CharReach &cr,
|
||||
const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> buildLbrTruf(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
enum RepeatType rtype = chooseRepeatType(repeatMin, repeatMax, minPeriod,
|
||||
is_reset);
|
||||
auto nfa = makeLbrNfa<lbr_truf>(LBR_NFA_TRUF, rtype, repeatMax);
|
||||
@@ -252,10 +248,9 @@ aligned_unique_ptr<NFA> buildLbrTruf(const CharReach &cr,
|
||||
}
|
||||
|
||||
static
|
||||
aligned_unique_ptr<NFA> constructLBR(const CharReach &cr,
|
||||
const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
bytecode_ptr<NFA> constructLBR(const CharReach &cr, const depth &repeatMin,
|
||||
const depth &repeatMax, u32 minPeriod,
|
||||
bool is_reset, ReportID report) {
|
||||
DEBUG_PRINTF("bounds={%s,%s}, cr=%s (count %zu), report=%u\n",
|
||||
repeatMin.str().c_str(), repeatMax.str().c_str(),
|
||||
describeClass(cr, 20, CC_OUT_TEXT).c_str(), cr.count(),
|
||||
@@ -263,8 +258,8 @@ aligned_unique_ptr<NFA> constructLBR(const CharReach &cr,
|
||||
assert(repeatMin <= repeatMax);
|
||||
assert(repeatMax.is_reachable());
|
||||
|
||||
aligned_unique_ptr<NFA> nfa
|
||||
= buildLbrDot(cr, repeatMin, repeatMax, minPeriod, is_reset, report);
|
||||
auto nfa =
|
||||
buildLbrDot(cr, repeatMin, repeatMax, minPeriod, is_reset, report);
|
||||
|
||||
if (!nfa) {
|
||||
nfa = buildLbrVerm(cr, repeatMin, repeatMax, minPeriod, is_reset,
|
||||
@@ -291,10 +286,10 @@ aligned_unique_ptr<NFA> constructLBR(const CharReach &cr,
|
||||
return nfa;
|
||||
}
|
||||
|
||||
aligned_unique_ptr<NFA> constructLBR(const CastleProto &proto,
|
||||
const vector<vector<CharReach>> &triggers,
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm) {
|
||||
bytecode_ptr<NFA> constructLBR(const CastleProto &proto,
|
||||
const vector<vector<CharReach>> &triggers,
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm) {
|
||||
if (!cc.grey.allowLbr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -330,10 +325,10 @@ aligned_unique_ptr<NFA> constructLBR(const CastleProto &proto,
|
||||
}
|
||||
|
||||
/** \brief Construct an LBR engine from the given graph \p g. */
|
||||
aligned_unique_ptr<NFA> constructLBR(const NGHolder &g,
|
||||
const vector<vector<CharReach>> &triggers,
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm) {
|
||||
bytecode_ptr<NFA> constructLBR(const NGHolder &g,
|
||||
const vector<vector<CharReach>> &triggers,
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm) {
|
||||
if (!cc.grey.allowLbr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user