source: proto/s2k/trunk/framework/input/test/s2k/proto/grep/grep_flow.s2k @ 4072

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

Minor updates.

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