source: proto/s2k/trunk/framework/input/test/s2k/proto/grep/s2k_header_grep.s2k @ 4065

Last change on this file since 4065 was 4065, checked in by ksherdy, 5 years ago

Updates to grep s2k.

File size: 5.5 KB
Line 
1/*
2 * grep exact-string search C++ in: s2k.
3 *
4 *
5 * The s2k grep exact-string search demo is organized into the following
6 * pipeline stages.
7 * 
8 * Stage 1 - Read
9 * Stage 2 - Transpose
10 * Stage 3 - ClassifyBytes
11 * Stage 4 - Match
12 * Stage 5 - MatchLines
13 * Stage 6 - Write
14 *
15 * The s2k program defines the following program elements.
16 *
17 * 1. Stream structures.
18 * 2. Stream filters. 
19 * 3. Stream graph.
20 *
21 * The s2k compiler translates s2k to b2k and b2k to C++ as follows.
22 *
23 * 1. s2k stream structures to b2k block structures, b2k block structures
24 *    to C++ structures, i.e., simple data containers.
25 *
26 * 2. s2k stream filters to b2k block kernels, b2k block kernels to
27 *    C++ structures, i.e., objects with methods.
28 *    C++ structures are generated with `do_block', `do_final_blocks',
29 *    and `clear' member functions, as well as member variables to capture
30 *    the propagation of state information across block boundaries for
31 *    incremental block-by-block processing.
32 *
33 * 3. s2k stream structure and stream filter definitions b2k stream structure
34 *    and block kernel definitions, b2k strem structure and block kernel
35 *    definitions to C++ structure instances.
36 *    s2k{} `graph' stream filter method calls to sequences of stream
37 *    function `do_block', `do_final_block', and `clear' function calls.
38 *   
39 */
40
41struct Input{
42  stream<8> data;
43}
44
45/*
46struct Basis_bits{
47  stream<1> bit_0;
48  stream<1> bit_1;
49  stream<1> bit_2;
50  stream<1> bit_3;
51  stream<1> bit_4;
52  stream<1> bit_5;
53  stream<1> bit_6;
54  stream<1> bit_7;
55};
56*/
57
58struct Lex{
59  stream<1> a;
60  stream<1> p;
61  stream<1> l;
62  stream<1> e;
63  stream<1> LF;
64};
65
66struct Output{
67  stream<1> match_follows;
68  stream<1> lines;
69  stream<1> line_starts;
70  stream<1> line_ends;
71};
72
73filter Read(out: struct Input input) {
74  //io.bind<8>(buffer, input.data, s2k::SEGMENT_SIZE);
75  //io.bind<1>(starts, output.starts, s2k::SEGMENT_SIZE);
76  //io.bind<1>(ends, output.ends, s2k::SEGMENT_SIZE);
77  //io.bind<1>(markers, output.markers, s2k::SEGMENT_SIZE);
78
79  //io.read<8>(input.data);
80}
81
82//filter Transpose(in: struct Input input, out: struct Basis_bits basis_bits) {
83//
84//}
85
86/* ClassifyBytes defines s2k equations for each of the character
87 * classes encountered in: the fixed string `apple' and line feeds.
88 * in: this example, the generation of character class bit stream
89 * equations is automated using the character class compiler tool.
90 */
91filter ClassifyBytes(in: struct Basis_bits basis_bits, out: struct Lex lex) {
92  stream<1> temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0));
93  stream<1> temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3));
94  stream<1> temp3 = (temp1 & temp2);
95  stream<1> temp4 = (basis_bits.bit_4 | basis_bits.bit_5);
96  stream<1> temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6));
97  stream<1> temp6 = (temp5 & (~ temp4));
98  lex.a = (temp3 & temp6);
99  stream<1> temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
100  stream<1> temp8 = (temp1 & temp7);
101  stream<1> temp9 = (basis_bits.bit_6 | basis_bits.bit_7);
102  stream<1> temp10 = (temp4 | temp9);
103  lex.p = (temp8 & (~ temp10));
104  stream<1> temp11 = (basis_bits.bit_4 & basis_bits.bit_5);
105  stream<1> temp12 = (temp11 & (~ temp9));
106  lex.l = (temp3 & temp12);
107  stream<1> temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4));
108  stream<1> temp14 = (temp13 & temp5);
109  lex.e = (temp3 & temp14);
110  stream<1> temp15 = (basis_bits.bit_0 | basis_bits.bit_1);
111  stream<1> temp16 = (basis_bits.bit_2 | basis_bits.bit_3);
112  stream<1> temp17 = (temp15 | temp16);
113  stream<1> temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5));
114  stream<1> temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7));
115  stream<1> temp20 = (temp18 & temp19);
116  lex.LF = (temp20 & (~ temp17));
117}
118
119filter Match(in: struct Lex lex, out: struct Output output) {
120  stream<1> cursor = flow.Advance(lex.a);
121  cursor = flow.Advance((cursor & lex.p));
122  cursor = flow.Advance((cursor & lex.p));
123  cursor = flow.Advance((cursor & lex.l));
124  cursor = flow.Advance((cursor & lex.e));
125  output.match_follows = cursor;
126}
127
128filter MatchLines(in: struct Lex lex, out: struct Output output) {
129  stream<1> all_line_starts = (flow.ScanToFirst((~ lex.LF))
130                            | (flow.Advance(lex.LF) & (~ lex.LF)));
131  stream<1> all_line_ends = lex.LF;
132  stream<1> last_line_start = flow.ScanToFirst(all_line_starts);
133  stream<1> cursor = last_line_start;
134  while (flow.inFile(cursor)) {
135      if ((cursor & all_line_starts)) {
136          last_line_start = cursor;
137      }
138      if ((cursor & output.match_follows)) {
139          cursor = flow.ScanTo(cursor, lex.LF);
140          output.lines |= flow.InclusiveSpan(last_line_start, cursor);
141      }
142      cursor = flow.AdvanceThenScanTo(cursor,
143                                      (all_line_starts | output.match_follows));
144  }
145  output.line_starts = (output.lines & all_line_starts);
146  output.line_ends = flow.ScanTo(output.line_starts,
147                                 (output.lines & all_line_ends));
148}
149
150filter Write(in: struct Output output) {
151  //io.write<1>(output.line_starts);
152  //io.write<1>(output.line_ends);
153  //io.write<1>(output.match_follows);
154}
155
156graph pipeline() {
157
158    struct Input input;
159    struct Basis_bits basis_bits;
160    struct Lex lex;
161    struct Output output;
162   
163    filter Read read;
164    filter Transpose transpose;
165    filter ClassifyBytes classifyBytes;
166    filter Match match;
167    filter MatchLines matchLines;
168    filter Write write;
169
170    read(input);
171    //transpose(input, basis_bits);
172    transpose(byte_data, basis_bits);
173    classifyBytes(basis_bits, lex);
174    match(lex, output);
175    matchLines(lex, output);
176    write(output);
177
178}
179
Note: See TracBrowser for help on using the repository browser.