1/*
2 * Copyright (c) 2016-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/**
30 * \file
31 * \brief Rose build: code for constructing literal tables.
32 */
33
34#ifndef ROSE_BUILD_MATCHERS_H
35#define ROSE_BUILD_MATCHERS_H
36
37#include "rose_build_impl.h"
38#include "rose_build_lit_accel.h"
39#include "hwlm/hwlm_build.h"
40#include "util/bytecode_ptr.h"
41#include "util/ue2string.h"
42
43#include <vector>
44
45struct Grey;
46struct HWLM;
47
48namespace ue2 {
49
50static constexpr u32 INVALID_FRAG_ID = ~0U;
51
52struct LitFragment {
53 LitFragment(u32 fragment_id_in, ue2_literal s_in,
54 rose_group groups_in, u32 lit_id)
55 : fragment_id(fragment_id_in), s(s_in), groups(groups_in),
56 lit_ids({lit_id}) {}
57 LitFragment(u32 fragment_id_in, ue2_literal s_in,
58 rose_group groups_in, std::vector<u32> lit_ids_in)
59 : fragment_id(fragment_id_in), s(s_in), groups(groups_in),
60 lit_ids(std::move(lit_ids_in)) {}
61 u32 fragment_id;
62
63 /**
64 * \brief literal fragment.
65 */
66 ue2_literal s;
67
68 /**
69 * \brief FDR confirm squash mask for included literals.
70 */
71 u8 squash = 0;
72
73 /**
74 * \brief FDR confirm squash mask for included literals (Delayed
75 * literals only).
76 */
77 u8 delay_squash = 0;
78
79 /**
80 * \brief Fragment id of included literal.
81 */
82 u32 included_frag_id = INVALID_FRAG_ID;
83
84 /**
85 * \brief Fragment Id of included literal (Delayed literals only).
86 */
87 u32 included_delay_frag_id = INVALID_FRAG_ID;
88 rose_group groups;
89 std::vector<u32> lit_ids;
90 u32 lit_program_offset = ROSE_INVALID_PROG_OFFSET;
91 u32 delay_program_offset = ROSE_INVALID_PROG_OFFSET;
92};
93
94struct LitProto {
95 LitProto(std::unique_ptr<HWLMProto> hwlmProto_in,
96 std::vector<AccelString> &accel_lits_in)
97 : hwlmProto(std::move(hwlmProto_in)), accel_lits(accel_lits_in) {}
98
99 std::unique_ptr<HWLMProto> hwlmProto;
100 std::vector<AccelString> accel_lits;
101};
102
103bytecode_ptr<HWLM>
104buildHWLMMatcher(const RoseBuildImpl &build, LitProto *proto);
105
106std::unique_ptr<LitProto>
107buildFloatingMatcherProto(const RoseBuildImpl &build,
108 const std::vector<LitFragment> &fragments,
109 size_t longLitLengthThreshold,
110 rose_group *fgroups,
111 size_t *historyRequired);
112
113std::unique_ptr<LitProto>
114buildDelayRebuildMatcherProto(const RoseBuildImpl &build,
115 const std::vector<LitFragment> &fragments,
116 size_t longLitLengthThreshold);
117std::unique_ptr<LitProto>
118buildSmallBlockMatcherProto(const RoseBuildImpl &build,
119 const std::vector<LitFragment> &fragments);
120
121std::unique_ptr<LitProto>
122buildEodAnchoredMatcherProto(const RoseBuildImpl &build,
123 const std::vector<LitFragment> &fragments);
124
125void findMoreLiteralMasks(RoseBuildImpl &build);
126
127} // namespace ue2
128
129#endif // ROSE_BUILD_MATCHERS_H
130