| 1 | /* | 
|---|
| 2 | * Copyright (c) 2015-2017, Intel Corporation | 
|---|
| 3 | * | 
|---|
| 4 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 5 | * modification, are permitted provided that the following conditions are met: | 
|---|
| 6 | * | 
|---|
| 7 | *  * Redistributions of source code must retain the above copyright notice, | 
|---|
| 8 | *    this list of conditions and the following disclaimer. | 
|---|
| 9 | *  * Redistributions in binary form must reproduce the above copyright | 
|---|
| 10 | *    notice, this list of conditions and the following disclaimer in the | 
|---|
| 11 | *    documentation and/or other materials provided with the distribution. | 
|---|
| 12 | *  * Neither the name of Intel Corporation nor the names of its contributors | 
|---|
| 13 | *    may be used to endorse or promote products derived from this software | 
|---|
| 14 | *    without specific prior written permission. | 
|---|
| 15 | * | 
|---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
|---|
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
|---|
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
|---|
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 
|---|
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
|---|
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
|---|
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
|---|
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
|---|
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
|---|
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
|---|
| 26 | * POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | #ifndef GOUGHCOMPILE_H | 
|---|
| 30 | #define GOUGHCOMPILE_H | 
|---|
| 31 |  | 
|---|
| 32 | #include "mcclellancompile.h" | 
|---|
| 33 | #include "nfa_kind.h" | 
|---|
| 34 | #include "ue2common.h" | 
|---|
| 35 | #include "util/bytecode_ptr.h" | 
|---|
| 36 | #include "util/flat_containers.h" | 
|---|
| 37 | #include "util/order_check.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include <map> | 
|---|
| 40 | #include <memory> | 
|---|
| 41 | #include <set> | 
|---|
| 42 | #include <vector> | 
|---|
| 43 |  | 
|---|
| 44 | namespace ue2 { | 
|---|
| 45 |  | 
|---|
| 46 | #define CREATE_NEW_SOM (~0U) | 
|---|
| 47 |  | 
|---|
| 48 | /* dest nfa state -> som info for dest state is min of provided loc idx som | 
|---|
| 49 | * info */ | 
|---|
| 50 | typedef flat_map<u32, std::vector<u32>> som_tran_info; | 
|---|
| 51 |  | 
|---|
| 52 | struct som_report { | 
|---|
| 53 | som_report(ReportID r, u32 s) : report(r), slot(s) {} | 
|---|
| 54 |  | 
|---|
| 55 | ReportID report; | 
|---|
| 56 | u32 slot; | 
|---|
| 57 |  | 
|---|
| 58 | bool operator<(const som_report &b) const { | 
|---|
| 59 | const som_report &a = *this; | 
|---|
| 60 | ORDER_CHECK(report); | 
|---|
| 61 | ORDER_CHECK(slot); | 
|---|
| 62 | return false; | 
|---|
| 63 | } | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | struct dstate_som { | 
|---|
| 67 | std::set<som_report> reports; | 
|---|
| 68 | std::set<som_report> reports_eod; | 
|---|
| 69 | som_tran_info preds; /* live nfa states mapped back to pred states */ | 
|---|
| 70 | }; | 
|---|
| 71 |  | 
|---|
| 72 | struct raw_som_dfa : public raw_dfa { | 
|---|
| 73 | raw_som_dfa(nfa_kind k, bool unordered_som_triggers_in, u32 trigger, | 
|---|
| 74 | u32 stream_som_loc_width_in) | 
|---|
| 75 | : raw_dfa(k), stream_som_loc_width(stream_som_loc_width_in), | 
|---|
| 76 | unordered_som_triggers(unordered_som_triggers_in), | 
|---|
| 77 | trigger_nfa_state(trigger) { | 
|---|
| 78 | assert(!unordered_som_triggers || is_triggered(kind)); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | std::vector<dstate_som> state_som; | 
|---|
| 82 | u32 stream_som_loc_width; | 
|---|
| 83 | bool unordered_som_triggers; | 
|---|
| 84 | void (void) override; | 
|---|
| 85 |  | 
|---|
| 86 | std::map<u32, u32> new_som_nfa_states; /* map nfa vertex id -> offset */ | 
|---|
| 87 | u32 trigger_nfa_state; /* for triggered cases, slot_id that contains a new | 
|---|
| 88 | * som */ | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 | bytecode_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision, | 
|---|
| 92 | const CompileContext &cc, | 
|---|
| 93 | const ReportManager &rm); | 
|---|
| 94 |  | 
|---|
| 95 | } // namespace ue2 | 
|---|
| 96 |  | 
|---|
| 97 | #endif // GOUGHCOMPILE_H | 
|---|
| 98 |  | 
|---|