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

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

Updated s2k engine demo.

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