source: proto/s2k/trunk/framework/input/test/s2k/test.s2k @ 3767

Last change on this file since 3767 was 3767, checked in by ksherdy, 4 years ago

Replaced function keyword with filter.

File size: 3.5 KB
Line 
1
2
3struct Basis{
4    stream bit_0;
5    stream bit_1;
6    stream bit_2;
7    stream bit_3;
8    stream bit_4;
9    stream bit_5;
10    stream bit_6;
11    stream bit_7;
12};
13
14struct Lex{
15    stream a;
16    stream p;
17    stream l;
18    stream e;
19    stream LF;
20};
21
22struct Matches{
23    stream all_matched;
24};
25
26struct Lines{
27    stream all_matched;
28};
29
30struct Output{
31    stream lines;
32};
33
34filter ClassifyBytes(struct Basis_bits basis_bits, struct Lex lex) {
35    stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0));
36    stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3));
37    stream temp3 = (temp1 & temp2);
38    stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5);
39    stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6));
40    stream temp6 = (temp5 & (~ temp4));
41    lex.a = (temp3 & temp6);
42    stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
43    stream temp8 = (temp1 & temp7);
44    stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7);
45    stream temp10 = (temp4 | temp9);
46    lex.p = (temp8 & (~ temp10));
47    stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5);
48    stream temp12 = (temp11 & (~ temp9));
49    lex.l = (temp3 & temp12);
50    stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4));
51    stream temp14 = (temp13 & temp5);
52    lex.e = (temp3 & temp14);
53    stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1);
54    stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3);
55    stream temp17 = (temp15 | temp16);
56    stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5));
57    stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7));
58    stream temp20 = (temp18 & temp19);
59    lex.LF = (temp20 & (~ temp17));
60}
61
62filter Match(struct Lex lex, struct Matches matches) {
63    stream m0 = lex.a;
64    stream m1 = (pablo.Advance(m0) & lex.p);
65    stream m2 = (pablo.Advance(m1) & lex.p);
66    stream m3 = (pablo.Advance(m2) & lex.l);
67    stream m4 = (pablo.Advance(m3) & lex.e);
68    matches.all_matched = m4;
69}
70
71filter MatchLines1(struct Lex lex, struct Matches matches, struct Lines lines) {
72    stream last_start = pablo.First();
73    stream LF_or_match = (lex.LF | matches.all_matched);
74    stream cursor = pablo.ScanToFirst(LF_or_match);
75    while (pablo.inFile(cursor)) {
76        if ((cursor & matches.all_matched)) {
77            stream next_end = pablo.AdvanceThenScanTo(cursor, lex.LF);
78            lines.all_matched |= (pablo.InclusiveSpan(last_start, next_end) | next_end);
79            cursor = next_end;
80        }
81        if ((cursor & lex.LF)) {
82            last_start = pablo.Advance(cursor);
83        }
84        cursor = pablo.AdvanceThenScanTo(cursor, LF_or_match);
85    }
86}
87
88filter MatchLines2(struct Lex lex, struct Matches matches, struct Lines lines) {
89    stream last_start = pablo.Mask(1,0);
90    last_start = (pablo.Advance((~ last_start)) ^ (~ last_start));
91    stream LF_or_match = (lex.LF | matches.all_matched);
92    stream cursor = pablo.ScanToFirst(LF_or_match);
93    while (pablo.inFile(cursor)) {
94        if ((cursor & matches.all_matched)) {
95            stream next_end = pablo.AdvanceThenScanTo(cursor, lex.LF);
96            lines.all_matched |= (pablo.InclusiveSpan(last_start, next_end) | next_end);
97            cursor = next_end;
98        }
99        if ((cursor & lex.LF)) {
100            last_start = pablo.Advance(cursor);
101        }
102        cursor = pablo.AdvanceThenScanTo(cursor, LF_or_match);
103    }
104}
105
106filter nameMatchLines(struct Data data, struct Output output) {
107    output.lines = pablo.filter_bytes(data, (~ lines.all_matched));
108}
109
110filter CountLines(struct Lex lex, struct Lines lines) {
111    return pablo.PopCount((pablo.MatchStar(lines, (~ lex.LF)) & lex.LF)) ;
112}
Note: See TracBrowser for help on using the repository browser.